javascript checkbox check

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
tomindo
Forum Newbie
Posts: 13
Joined: Sun Mar 21, 2010 1:22 am

javascript checkbox check

Post by tomindo »

Code: Select all

function chk_view() {
	    var theForm = document.myform;
	for (i=0; i<theForm.elements.length; i++) {
        if ((theForm.elements[i].value==4) && (theForm.elements[i].checked ==1)){
            theForm.elements[i].value==1;
            theForm.elements[i].checked = true;
			}
	
	}
	}
Basically, I want when check box with value =4 is checked , the check box with value =1 will be checked too. But the above code does not work
tomindo
Forum Newbie
Posts: 13
Joined: Sun Mar 21, 2010 1:22 am

Re: javascript checkbox check

Post by tomindo »

could moderator move my thread to java script forum?
thanks
Done.
User avatar
Technical
Forum Commoner
Posts: 81
Joined: Thu Dec 02, 2010 5:30 am

Re: javascript checkbox check

Post by Technical »

tomindo wrote:Basically, I want when check box with value =4 is checked , the check box with value =1 will be checked too. But the above code does not work
Aren't checkbox with value 4 and 1 same? Or you need to change value from 4 to 1?
You're operating with only one checkbox in your code.
thecodewall
Forum Commoner
Posts: 33
Joined: Sun Dec 26, 2010 8:37 am

Re: javascript checkbox check

Post by thecodewall »

You can apply onclick function to checkbox 4, this function will check checkbox 1 when in click.
Post Reply