Pål Sindre Hiåsen wrote:
[...] Martin Honnen [...] wrote: Pål Sindre Hiåsen wrote: I want to put this into a for loop and do something like this
for(i=0;i<numfield;i++)
{
value[i] = parseInt(document.form1.["text"+i].value);
parseInt() by default also parses hexadecimal (with leading `0x') and in
some implementations deprecated octal (with leading zero) values. If you
don't want that, pass a second operand to indicate the target base:
value[i] = parseInt(..., 10);
Parsing any non-decimal value then will result in `NaN' which evaluates
to `false' in a boolean expression.
You need to drop that dot that is you need to use
document.form1["text" + i].value
The both standards compliant and downwards compatible way is
document.forms["form1"].elements["text" + i].value
You should assign overly long and mroe often used references to a variable:
var fe = document.forms["form1"].elements;
if (fe["text" + i])
{
... fe["text" + i].value ...
}
And if you pass the reference to the handling method, referencing becomes
much easier:
....
<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
</head>
<body>
...
<form action="..." ...>
<div>
...
<script type="text/javascript">
function handleMe(f)
{
var fe;
if (f && (fe = f.elements))
{
...
if (fe["text" + i])
{
... fe["text" + i].value ...
}
...
}
}
document.write('<input ... onclick="handleMe(this.form);">');
</script>
...
</div>
</form>
...
</body>
PointedEars