|
-
Jun 8th, 2006, 12:05 AM
#1
Thread Starter
Member
[RESOLVED] Javascript Checkbox Problem...
PHP Code:
<?
include "Config.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
</head>
<body>
<script language='javascript'>
function Cek01()
{
document.forms['FrmCheck'].ChkPil[0].checked=true;
}
</script>
<Form name='FrmCheck' action='inp_MCU.php' method='POST'>
<table width=800 border=1>
<?
$SQL="Select * From MCU_MSPackage order by CdCheck";
$result=mysql_query($SQL);
$tmpGroup="00";
$ax=0;
if (mysql_num_rows($result)>0)
{
while($row=mysql_fetch_array($result))
{
if($tmpGroup<>$row["CdGroup"])
{
echo "<tr>";
echo "<td>";
?>
<input type='checkbox' name='ChkGrp[]' onClick='Cek01();' /><input type='text' name='TxtABC' />
<?
echo"</td><td colspan=2>".$row["NmGroup"] . "</td>";
$tmpGroup=$row["CdGroup"];
echo "</tr>";
}
?>
<tr><td width=25></td>
<td><input name='ChkPil[]' type='checkbox' value= <? echo $row["CdCheck"]; ?> /></td><td> <? echo $row["NmCheck"]."/".$row["NmEngland"];?></td>
</tr>
<?
}
}
?>
<input type='submit' value='Send' />
</table>
</Form>
</body>
</html>
Hello... I have some problem... with Javascript...
I want if I Checked the "ChkGrp".. The Checkbox "ChkPil[0]" is checked...
But I can't do it....
Except i change name of "ChkPil[]" to "ChkPil". But I need array of Checkbox ... to next page...
Any Solution...???
Thanks...
-
Jun 8th, 2006, 07:04 PM
#2
Fanatic Member
Re: Javascript Checkbox Problem...
pls explain more..what are you trying to do
-
Jun 8th, 2006, 07:15 PM
#3
Thread Starter
Member
Re: Javascript Checkbox Problem...
There is 2 type Checkbox...
ChkGrp and ChkPil (Array of Checkbox) ....
If I check "ChkGrp", I want ChkPil[0] was checked too... (only index 0 )...
So I call function Cek01 on ChkGrp...
But It doesn't work...EXCEPT if change name of "ChkPil[]" to "ChkPil"...
But IF I CHANGE NAME to ChkPil.... when I send to other Page... with :
$_POST["ChkPil"]; It's only return 1 value
But with "ChkPil[]" when I send to other page , i can make array of this variable :
$test=$_POST["ChkPil"];
$text="";
for($i=0;$i<sizeof($test);$i++)
{
$text = $text . $test[$i];
}
Just like that...
-
Jun 8th, 2006, 07:31 PM
#4
<?="Moderator"?>
Re: Javascript Checkbox Problem...
have you tried, using getElementByName or getElementById to access the element to change the value of it?
-
Jun 8th, 2006, 07:37 PM
#5
Fanatic Member
Re: Javascript Checkbox Problem...
try saying this
Code:
document.forms['FrmCheck'].ChkPil+'[0]'.checked=true
i had this problem in my code sometimes ago, thats what i did, and it did work fine..
hope it helps
-
Jun 8th, 2006, 09:01 PM
#6
Thread Starter
Member
Re: Javascript Checkbox Problem...
Doesn't works... (
if i'm using
Code:
alert("document.forms['FrmCheck'].ChkPil+'[0]'.checked);
it will show alert "NaN";
If i'm using Javascript Console on Firefox , it will show :
"Invalid assignment left-hand side"...
-
Jun 8th, 2006, 11:03 PM
#7
Fanatic Member
Re: Javascript Checkbox Problem...
that will be either outputing True or False
and i don't think js will try to convert that to 0 or 1
so i think that's why you get NaN(Not a Number)
-
Jun 8th, 2006, 11:24 PM
#8
Re: Javascript Checkbox Problem...
I think it should be
Code:
alert(document.getElementByName('ChkPil[0]').checked);
There should be no data type conversion happening. See what that returns.
-
Jun 9th, 2006, 12:08 AM
#9
Re: Javascript Checkbox Problem...
Also, if you want to get a form element:
Code:
document.forms[0].elements['ChkGrp[]'];
If it is a list of checkboxes you'll get an array of elements.
-
Jun 9th, 2006, 01:52 AM
#10
Thread Starter
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|