Click to See Complete Forum and Search --> : getElementById I can not use it?WHY


said_fox
04-24-2003, 05:40 PM
getElementById("theid")
assign all elements of the same id value in an array. Is this true?.

So please till me why this script does not work properly?


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<script language="JavaScript" type="text/javascript">
function mafox(gla)
{
tonl=document.getElementById("t1");
conl=document.getElementById("c1");
x=0;
alert(x);
do
{
alert(conl[x].value);
if (conl[x]==gla){
alert(x);

}
x++;
}
while(x<conl.length)

}
</script>
<title>ToForm</title>
</head>
<body>
<form action="form2.php" method="post" name="f1">
<?

for ($i = 0; $i < 10; ++$i)
{
?>
<input type="text" name="txt[]" value="<?=$i?>" id="t1" >
<input type="text" name="txt1[]" value="<?=$i?>" id="t1" >
<input type="checkbox" value="y<?=$i?>" name="chk[]" id="c1" onMouseOver="mafox(this)">

<input type="hidden" name="hide[]" value="y<?=$i?>">
Chhos Num <?=$i?><br>
<?}
?>
<input type="submit">
</form>
</body>
</html>


So please what's wrong I did?:mad: :mad: :confused:

Jona
04-24-2003, 05:53 PM
Did you forget the PHP part?

<?PHP

for....

?>

said_fox
04-24-2003, 06:20 PM
Ok,
Don't concentrate on the PHP code in this example, it's only to produce dynamically number of rows contain some form elements, in repeated mannar.

The most important and vital, is the clientside script, JavaScript, the problem in it, and I don't know how to solve it.
:confused:
And thank you for help, and I hope to receive more help if you know more, to solve this problem

Jona
04-24-2003, 06:27 PM
I understand the code perfectly, including the PHP, however I don't know why it wouldn't work. And, although I haven't tested it, someone is sure enough to come around and help you... *Looks at Dave Clark...* :rolleyes:

Vladdy
04-25-2003, 05:32 AM
Element ID should be UNIQUE. getElementById returns SINGLE object, not an array.

said_fox
04-25-2003, 09:32 AM
Ok,
So,I'd like to ask, are getElementsByName or getElementsByTagName, rturns array?

Thank you for this valuable reply
:)

Jona
04-25-2003, 10:45 AM
Oooh, you're right, Vladdy. I didn't notice that part (wonder why?). Hmmmm, return an array of objects? There is document.formname.elements[x], where elemens.length is the number of form elements in the form--but if you're looking for an array of checkboxes... :rolleyes: