Page 1 of 1

javascript checkbox check

Posted: Sun Dec 19, 2010 3:52 am
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

Re: javascript checkbox check

Posted: Sun Dec 19, 2010 1:22 pm
by tomindo
could moderator move my thread to java script forum?
thanks
Done.

Re: javascript checkbox check

Posted: Mon Dec 27, 2010 4:50 am
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.

Re: javascript checkbox check

Posted: Wed Jan 05, 2011 12:22 am
by thecodewall
You can apply onclick function to checkbox 4, this function will check checkbox 1 when in click.