how to turn checkbox.checked = true

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

how to turn checkbox.checked = true

Post 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;
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Re: how to turn checkbox.checked = true

Post 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.
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

Post 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[] ?
TheBentinel.com
Forum Contributor
Posts: 282
Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio

Post 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.
Post Reply