Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

show/hide checkbox question

Status
Not open for further replies.

karren

Programmer
Feb 26, 2002
42
CA
hi there,

i am trying to get a checkbox to show an input box when it is clicked on but i can't get it to work. here is the code i have so far:


<script type="text/javascript">
function showhide2(thismenu)
{
if(document.forms[0].ChangeInPracticeOther.value=='Left practice')
{
document.getElementById(thismenu).style.display="block";
}
else
{
document.getElementById(thismenu).style.display="none";
}

}
</script>


Reduced hours<input type="checkbox" name="ChangeInPracticeOther" value="reducedhours" />
Certain services/disease states not seen<input type="checkbox" name="ChangeInPracticeOther" value="servicesdisease" />
Left practice<input type="checkbox" name="ChangeInPracticeOther" value="Left practice" onClick="javascript: showhide2('menu4')" />

<div id='menu4' style='display: none'>
<br />
<br />
<i>If you selected "Left Practice", what work are you currently doing
now?</i><br />
</div>

can anyone help me out?? any help will be appreciated!

thank you!!!!!

karren
 
Checkboxes are funny creatures. If you're certain of the final order of them, you can replace the corresponding line of JavaScript with:

Code:
if(document.forms[0].ChangeInPracticeOther[b][1].checked[/b])

...or you can do this:

Code:
for(var j=0; j<document.forms[0].ChangeInPracticeOther.length; j++)
{
 if(document.forms[0].ChangeInPracticeOther[b][j][/b].value=='Left practice' && document.forms[0].ChangeInPracticeOther[j].checked)
 {
  ...
 }//end if
}//end for

Note the use of the index following ChangeInPracticeOther. Since there are more than one, each is an array member.

'hope that helps.

--Dave
 
hi dave,

thanks so much for your reply, but both your suggestions didn't seem to work. the div with the textbox i wanna show when the user clicks on the "Left practice" checkbox still does not appear. i do not get any javascript errors but the div remains hidden. i'm not sure what i am doing wrong since there are no errors.

karren
 
oh WAIT!!!
THANK YOU DAVID!!

your code worked :) i just had a slight syntax error. i'm an idiot!!!

THANKS!!!!
 
:) I'm sure you're not an idiot!

'glad to help!

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top