Hi guys, new here and to javascript, I have this form that I am trying to you javascript to validate the multiple input text boxes.
form as follows
and the javascript
when I use document.getEle mentById("input[]")
it fails
when I use document.getEle mentByName("inp ut[]")
it succeeds,
However I need the input boxes to have unqiue names so that I can post to php server by names.
Is document.getEle mentById("input[]") not designed to work with arrays or am I overlooking something?
form as follows
Code:
<form action="login.php" method="post" onsubmit="return(checkAll(this))"> <label>Username<br /><input id="input[]" type="text" name="username" /></label><br /> <label>Email<br /><input id="input[]" type="text" name="email" /></label><br /> <label>Password<br /><input id="input[]" type="password" name="pswd1" /></label><br /> <label>Password Again<br /><input id="input[] "type="password" name="pswd2" /></label><br /> <input type="submit" name="submit" value="Submit" /> <input type="reset" value="Reset" /> </form>
Code:
function checkAll(formObj)
{
alert("formObj here");
check_obj = document.getElementByID("input[]");
alert("formObj here1");
for (i=0; i<check_obj.length; i++)
{
alert("inside formObj here");
if (check_obj[i].value == "")
{
alert("Input item on Row #"+(i+1)+" has been left empty. Please make sure you input something into this field.");
return false;
}
}
}
it fails
when I use document.getEle mentByName("inp ut[]")
it succeeds,
However I need the input boxes to have unqiue names so that I can post to php server by names.
Is document.getEle mentById("input[]") not designed to work with arrays or am I overlooking something?
Comment