javascript - How do I refer to the input values within a table cell for looped validation? -
i have html table repeated rows of input similar following:
<table id="tableinput"> <thead> <tr> <th>col 1</th> <th>col 2</th> </tr> </thead> <tbody id='abc'> <tr> <td><input id="itemid" name="itemid" type="text" size="20" /></td> <td>col2 desc</td> </tr> <tr> <td><input id="itemid" name="itemid" type="text" size="20" /></td> <td>col2 desc</td> </tr> </tbody> </table>
how can reference input id's in validation loop? like:
i=0; while < document.getelementbyid("tableinput").tbodies.length { x = document.getelementbyid("tableinput").tbodies[i].input.value); if x = "" { errormsg = 1; } i++; }
the id of element has unique.
<input id="itemid" name="itemid" type="text" size="20" />
so in each row want different value itemid
. secondly check if-statement. parentheses missing , assing value x instead of comparing it.
for loop can utilize getelementbytagname
(see vsync's answer)
javascript html
No comments:
Post a Comment