PDA

View Full Version : Checkbox problem



Vile Demonic
05-22-2008, 09:52 PM
im new to this whole javascript thing.


can anyone tell me how to to do this.

im wanting to set up a checkbox so that when its selected it displays 400 in a seperate text box if its not selected it stays empty. Also additional to that i need a secondary checkbox that can be selected and display 600 in the before mentioned text box. i need it set up so that only one of these can be selected and displayed at a time.

its for a booking fomr i need to do. cant suss out how to do this

rangana
05-23-2008, 01:57 AM
Could you rephrase it?..The question has two meaning:

1.) When the checkboxes are clicked a "400" or "600" is displayed on a text box.

2.) When the checkboxes are clicked a 400 or 600 textbox appears.

I suppose it's no.1, See if this help:


<script type="text/javascript">
window.onload=function()
{
var check400=document.getElementById('check400'),
check600=document.getElementById('check600'),
output=document.getElementById('output');
output.disabled='disabled';
check400.onclick=function()
{
if(this.checked){
check600.checked=false;
output.value='400';
}else output.value='';
}
check600.onclick=function()
{
if(this.checked){
check400.checked=false;
output.value='600';
}
else output.value='';
}
}
</script>
<input type="checkbox" name="mycheck" id="check400"><label>400</label>
<input type="checkbox" name="mycheck" id="check600"><label>600</label>
<br>
<label>Shows Here: </label><input type="text" id="output">

Vile Demonic
05-23-2008, 06:59 AM
Yeah thats about right

although i still cant get the 400 or 600 to appear in the box. I may be going about this a very difficult way.


This is part of an open book assessment im doing and i cant figure out the simplest solution.

rangana
05-23-2008, 07:01 AM
Which is not working?..Could you show us your codes :)

Vile Demonic
05-23-2008, 07:05 AM
ach i just deleted all the codes. think im going to start it all try find a more simple way.

all i need is a way to display 400 or 600 either by using a check box or drop down menu in a seperate text box (like a total would) so it can be added onto another number (not always used) then display the total of those 2

rangana
05-23-2008, 07:59 AM
Whatever you decision is, just get back if you're still stumped :)