My question is: how do I refer to the dynamic "name" of an input element in a form?
For example, with the following HTML:
<form>
<input type="text" name="qty1" value="input1" />
<input type="text" name="qty2" value="input2" />
<input type="text" name="qty3" value="input3" />
<input type="submit" value="Submit" onClick="checkVal(this.form); return false;" />
</form>
Javascript:
function checkVal(form) {
for (var i = 1; i <= 3; i++) {
alert(form.qty+i.value);
}
}
The above javascript is not working. The message displays NaN.
How to refer to qty1, qty2and qty3in the loop for, using a variable i?
Here's jsfiddle: http://jsfiddle.net/MRzWf/
source
share