Javascript Radio button to disable form elements fields

smares32371
smares32371 used Ask the Experts™
on
If this radio button checked disable form elements under the third radio button
<input name="bill" id="bill"  type="radio"  value="above">Bill me at the above address

If this radio button checked disable form elements under the third radio button
<input name="bill" id="bill" type="radio" value="newbilling" >Bill me at this address:

If the above radio buttons are selected disable form elements below.
<input name="bill" id="bill" type="radio"   value="creditcardpayment" checked >
<input type="text" class="textEntry1" name="billingname" id="billingname"  size="42">
<input type="text" name="billingstreetaddress" id="billingstreetaddress" size="42" maxlength="255" />
<input type="text" name="billingcity"  id="billingcity" size="25" maxlength="64" /
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,
<script type="text/javascript">

function check()
{
	var r1 = document.getElementById('bill1');
        var r2 = document.getElementById('bill2');
        var r3 = document.getElementById('bill3');

	if(r1.checked || r2.checked){
		document.getElementById('billingname').setAttribute('disabled', 'disabled');
		document.getElementById('billingstreetaddress').setAttribute('disabled', 'disabled');
		document.getElementById('billingcity').setAttribute('disabled', 'disabled');
	} else {
		document.getElementById('billingname').removeAttribute('disabled');
		document.getElementById('billingstreetaddress').removeAttribute('disabled');
		document.getElementById('billingcity').removeAttribute('disabled');
	}
}
</script>

Open in new window


and
 
 If this radio button checked disable form elements under the third radio button
<input name="bill" id="bill1"  type="radio"  value="above" onchange="check();">Bill me at the above address<br/>

If this radio button checked disable form elements under the third radio button
<input name="bill" id="bill2" type="radio" value="newbilling" onchange="check();">Bill me at this address:<br/>

If the above radio buttons are selected disable form elements below.
<input name="bill" id="bill3" type="radio"   value="creditcardpayment" checked onchange="check();"><br/>
<input type="text" class="textEntry1" name="billingname" id="billingname"  size="42">
<input type="text" name="billingstreetaddress" id="billingstreetaddress" size="42" maxlength="255" />
<input type="text" name="billingcity"  id="billingcity" size="25" maxlength="64" />

Open in new window



Author

Commented:
your good!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial