Page 1 of 1

how to turn checkbox.checked = true

Posted: Mon Mar 15, 2004 10:58 pm
by valen53
The function i want is when i change the select box, the checkbox will checked. But javascript syntax error. anyone can guide me ... ?

i use name = "editbox[]" b'cos i use foreach().

<input name="editbox[]" type="checkbox">

Below is the Source

Code: Select all

<script language="JavaScript">
function tickIt(form)
&#123; 
 document.forms&#1111;0].editbox&#1111;].checked = true ;
&#125;
</script>
 
while loop &#123;
<select name="select" onChange ="tickIn(this.form)">
<option value="1" >H</option>
<option value="2" >A</option>
</select>
<input name="editbox&#1111;]" type="checkbox" id="editbox" value="<? echo $row_mat_id ?>">
&#125;

Re: how to turn checkbox.checked = true

Posted: Tue Mar 16, 2004 12:20 pm
by TheBentinel.com
valen53 wrote: document.forms[0].editbox[].checked = true ;
Javascript doesn't like the brackets in that line with no index. I changed it to:

document.forms[0]["editbox[]"].checked = true ;

and it worked for me. Please try that and see if it works for you.

Posted: Tue Mar 16, 2004 9:59 pm
by valen53
thanks for reply...

Code: Select all

document.forms&#1111;0]&#1111;"editbox&#1111;]"].checked = true ;
the code was no error, but didn't function. maybe it can't get which checkbox should be checked.

if i use :

Code: Select all

document.forms&#1111;0].editbox&#1111;0].checked = true ;


the only first checkbox will be checked.
or i need to assign some id in to editbox[] ?

Posted: Tue Mar 16, 2004 10:58 pm
by TheBentinel.com
valen53 wrote:thanks for reply...

Code: Select all

document.forms&#1111;0]&#1111;"editbox&#1111;]"].checked = true ;
the code was no error, but didn't function. maybe it can't get which checkbox should be checked.
If you've got more than one, try putting an index in the reference to them:

Code: Select all

document.forms&#1111;0]&#1111;"editbox&#1111;]"]&#1111;0].checked = true ;
That's ugly, but it's worth a shot.