My question is: How do I reference a dynamic 'name' of an input element in a form?
For instance, 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); // Here's where my problem is..
}
}
The above javascript does not work. The alert is outputting NaN.
How do I reference qty1, qty2, and qty3 in a for loop using i variable?
Here's a jsfiddle: http://jsfiddle.net/MRzWf/