Lanceli
09-02-2006, 09:32 PM
Hi all,
I have a form with a few <input type="text" name="data[]"/>. I want to make a javascript to change all of their values at once. Please note, I have to use "data[]" as the name of the input. However, it's invalid to use document.forms.myForm.data[].value. So how shall I walk around this problem? How can I refer to that input object?
Here is my code: (only works when input name="data")
<html>
<head>
<script type="text/javascript">
function setvalue()
{
for (i=0; i<document.forms.myForm.data.length; i++){
document.forms.myForm.data[i].value=1;
}
}
</script>
</head>
<body>
<form name="myForm" action="" method="get"
target="_blank">
<input type="text" name="data[]" size="20"><br />
<input type="text" name="data[]" size="20"><br />
<input type="button" onclick="setvalue()" value="set val">
</form>
</body>
</html>
I have a form with a few <input type="text" name="data[]"/>. I want to make a javascript to change all of their values at once. Please note, I have to use "data[]" as the name of the input. However, it's invalid to use document.forms.myForm.data[].value. So how shall I walk around this problem? How can I refer to that input object?
Here is my code: (only works when input name="data")
<html>
<head>
<script type="text/javascript">
function setvalue()
{
for (i=0; i<document.forms.myForm.data.length; i++){
document.forms.myForm.data[i].value=1;
}
}
</script>
</head>
<body>
<form name="myForm" action="" method="get"
target="_blank">
<input type="text" name="data[]" size="20"><br />
<input type="text" name="data[]" size="20"><br />
<input type="button" onclick="setvalue()" value="set val">
</form>
</body>
</html>