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

Disable/Enable form elements 1

Status
Not open for further replies.

gus121

Technical User
May 9, 2002
298
0
0
GB
Hi I am attempting to write some code which disables enables a list box from a checkbox. I just get an error message syntax error. can anyone help and explain what I did wrong.

thanks

<script type=&quot;text/javascript&quot;>
function enableField() {

If (document.form1.checkbox.value == true)
{ document.form1.select.disabled=false; }
else
{ document.form1.select.disabled=true; }
}
</script>

</p>
<p>&nbsp;</p>
<form action=&quot;&quot; method=&quot;post&quot; name=&quot;form1&quot;>
<input name=&quot;checkbox&quot; type=&quot;checkbox&quot; value=&quot;Enable&quot; onClick=&quot;enableField();&quot;>
<select name=&quot;select&quot; size=&quot;1&quot; multiple disabled=&quot;true&quot;>
<option value=&quot;tennis&quot;>tennis</option>
<option value=&quot;soupe&quot;>soupe</option>
</select>
</form>

Angus
 


function enableField() {
if(document.form1.select.disabled == true){
alert()
document.form1.select.disabled=false;
}else{
document.form1.select.disabled=true;
}}
 
make the following changes to your code:
Code:
function enableField() {
   if (document.form1.checkbox.checked) {
      document.form1.select.disabled=false;
   }
   else {
      document.form1.select.disabled=true;
   }
}
Note that javascript is case sensitive, your if statments must begin with a lower-case i

-kaht

banghead.gif
 
hi there I wish to step this up a level create a function which can disable/enable multiple form elements at one time from different radio boxes these are created dynamicly with server side code.

The fuctionality I need is that when a checkbox is checked the corresponding ID attribute Select drop down form element is enabled. When It is not selected it is disabled. Please see bellow.

<form name=&quot;Product_Options&quot; id=&quot;Product_Options&quot; action=&quot;basket_popup.asp?Action=Add&PID=88&quot; method=&quot;post&quot; onSubmit=&quot;prepareWin() &quot; target=&quot;basket_popup&quot;>


<input type='radio' onClick='enableField();' id='0' name=Product_Option value='134' checked></td>
Flat coversbr>
Options:<br>Polyester Cotton
<select id='0' name='Sub_Option_311'><option value='1829' selected>420 £176.06 inc. VAT</option>
<option value='1830'>470 £185.33 inc. VAT</option>

<option value='1866'>Wayfarer £187.39 inc. VAT</option>
</select>
<br>PVC coated polyester
<select id='0' name='Sub_Option_52'><option value='1868' selected>420</option>
<option value='1869'>470</option>

<option value='1873'>Wayfarer</option>
</select>

<input type='radio' onClick='enableField();' id='1' name=Product_Option value='133'>
<span class=pagelinks1>Overboom covers</span><br>
<span class=pagelinks1>Options</span>:<br>Polyester Cotton
<select id='1' name='Sub_Option_312' disabled><option value='1920' selected>420 £184.62 inc. VAT</option>
<option value='1921'>470 £191.68 inc. VAT</option>
<option value='1923'>49'er</option>

<option value='1972'>Wanderer £157.37 inc. VAT</option>
<option value='1973'>Wayfarer £193.69 inc. VAT</option>
</select>
<br>PVC coated polyester
<select id='1' name='Sub_Option_313' disabled><option value='1975' selected>420 £126.10 inc. VAT</option>
<option value='1976'>470 £130.13 inc. VAT</option>
<option value='1978'>49'er</option>

<option value='2027'>Wanderer £112.99 inc. VAT</option>
<option value='2028'>Wayfarer £140.22 inc. VAT</option>
</select>

<input type='radio' onClick='enableField();' id='2' name=Product_Option value='612'>
<span class=pagelinks1>Trailing covers</span><br>
<span class=pagelinks1>Options</span>:<br>PVC coated polyester
<select id='2' name='Sub_Option_314' disabled><option value='2030' selected>420 £81.33 inc. VAT</option>
<option value='2031'>470</option>

<option value='2082'>Wanderer</option>
<option value='2083'>Wayfarer £93.69 inc. VAT</option>
</select>

<input type='radio' onClick='enableField();' id='3' name=Product_Option value='613'>
<span class=pagelinks1>Undercovers</span><br>
<span class=pagelinks1>Options</span>:<br>Nylon
<select id='3' name='Sub_Option_315' disabled><option value='2085' selected>420 £109.13 inc. VAT</option>
<option value='2086'>470 £113.26 inc. VAT</option>
<option value='2137'>Wanderer £105.02 inc. VAT</option>
<option value='2138'>Wayfarer £123.55 inc. VAT</option>
</select>

<input type=&quot;image&quot; src=&quot;/img/add-to-basket.gif&quot; width=145 height=26 border=0 >
</form>


Can anyone help. Thanks



-Gus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top