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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dropdown box selection choice checks a box

Status
Not open for further replies.

dontpunchme

Programmer
Jul 29, 2002
20
US
I have a form that has a dropdown box in it and a checkbox. When a certain item in the dropdown is selected I want the checkbox to change to "checked".

Any ideas?

Thanks.

 
in the dropdown:

<select name=&quot;drp&quot; .... onchange=&quot;CheckIt()&quot;>




<script>
function CheckIt()
{
if(document.FormName.drp.options[document.FormName.drp.selectedIndex].value==&quot;THE_VALUE&quot;)
{
document.FormName.Checkbox.checked==true
}
}
</script>

hth

FormName - Name of the form.

Known is handfull, Unknown is worldfull
 
And if you want to make SURE it is checked (i.e., you want to prevent the user from UNchecking it), alter vbkris' script to:

Code:
<script>
function CheckIt()
{
 if(document.FormName.drp.options[document.FormName.drp.selectedIndex].value==&quot;THE_VALUE&quot;)
 {
   document.FormName.Checkbox.checked = true;
   document.FormName.Checkbox.disabled = true;
 }
 else
 {
   document.FormName.Checkbox.disabled = false;
 }
}
</script>

Notice vbkris' typo also. The action inside the curly-braces should be &quot;checked = true&quot; (not &quot;==&quot;). I'm certain he was merely typing on autopilot and did not intend to suggest &quot;==&quot;.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top