JavaScript and client side scripting.
Moderator: General Moderators
-
valen53
- Forum Contributor
- Posts: 137
- Joined: Tue Aug 27, 2002 9:29 am
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)
{
document.formsї0].editboxї].checked = true ;
}
</script>
while loop {
<select name="select" onChange ="tickIn(this.form)">
<option value="1" >H</option>
<option value="2" >A</option>
</select>
<input name="editboxї]" type="checkbox" id="editbox" value="<? echo $row_mat_id ?>">
}
-
TheBentinel.com
- Forum Contributor
- Posts: 282
- Joined: Wed Mar 10, 2004 1:52 pm
- Location: Columbus, Ohio
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ї0]ї"editboxї]"].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ї0].editboxї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ї0]ї"editboxї]"].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ї0]ї"editboxї]"]ї0].checked = true ;
That's ugly, but it's worth a shot.