Current location: Hot Scripts Forums » General Web Coding » JavaScript » js code to disable checkbox

js code to disable checkbox

Reply
  #1 (permalink)  
Old 11-13-09, 03:46 AM
rsmahaa rsmahaa is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
js code to disable checkbox

I need javascript code to disable (2) check box when radiobutton is selected..

...It would be great if someone Help me with that...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-13-09, 07:36 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,030
Thanks: 14
Thanked 34 Times in 33 Posts
Quote:
Originally Posted by rsmahaa View Post
I need javascript code to disable (2) check box when radiobutton is selected..
Please post your code. In the meantime, this may help:

[edit, see corrected code below]
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data (scroll down)

Last edited by End User; 11-13-09 at 10:53 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-13-09, 08:03 AM
rsmahaa rsmahaa is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
This code is not working....
selection of both radiobuttons, disable check boxes

<html>
<head>
<script>
function update() {

var rb = document.getElementById("myRadioButton").value;

if (rb == 1) {

document.getElementById("x1").disabled = true;
document.getElementById("x2").disabled = true;
}else{

document.getElementById("x1").disabled = false;
document.getElementById("x2").disabled = false;
}
}
</script>
</head>
<body>
<form>
<input type="radio" name="myRadioButton" id="r1" value="1" onclick="update();" />
<input type="radio" name="myRadioButton" id="r2" value="2" onclick="update();" />

<input type="checkbox" name="myCheckBox1" id="x1" value="a" />
<input type="checkbox" name="myCheckBox1" id="x2" value="b" />
</form>
</body>
</html>

Last edited by rsmahaa; 11-13-09 at 08:14 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-13-09, 10:53 AM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,030
Thanks: 14
Thanked 34 Times in 33 Posts
Here some corrected code:

HTML Code:
<html>
<head>

<script type="text/javascript">

function update(val) {
	if (val==1) {
		document.getElementById("x1").disabled = true;
		document.getElementById("x2").disabled = true;
	}else{
		document.getElementById("x1").disabled = false;
		document.getElementById("x2").disabled = false;
	}
}
</script>
</head>
<body>

<form>
<input type="radio" name="myRadioButton" id="r1" value="1" onclick="update(1);" />Disable
<br>
<input type="radio" name="myRadioButton" id="r2" value="2" onclick="update(2);" />Enable
<p>

<input type="checkbox" name="myCheckBox1" id="x1" value="a" />Checkbox #1 
<br>
<input type="checkbox" name="myCheckBox1" id="x2" value="b" />Checkbox #2
</form>
</body>
</html>
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data (scroll down)

Last edited by End User; 11-13-09 at 10:55 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-13-09, 10:55 PM
rsmahaa rsmahaa is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
ya its working fine. thankyou
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl LWP loses html code?! jialanw Perl 22 04-13-09 03:14 PM
Google Ad Rotation Code LaPirata Script Requests 3 11-07-08 03:27 PM
JS to hide certain code acording to the keywords in the domain? carlatf JavaScript 7 10-06-08 10:01 AM
Zip Code search range errors Merovingian PHP 2 02-09-06 04:33 PM
protecting code in PHP ckb PHP 12 01-02-04 09:53 AM


All times are GMT -5. The time now is 12:49 PM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.