...

View Full Version : Input text box in FOR LOOP with same Name



laker_66
05-31-2004, 05:32 AM
Hi,
I have a FORM which has a Input text box in a FOR loop .


<form name="form1" method="POST" Action="sasd.asp" onSubmit="return validate();">
<%
for(i=0;i <3;i++)
{
%>
<input width="150" Type="text" name="NM">
<%
}
%>

</FORM>



This might be simple but I'm having difficulity in reading what is inside the "NM" Input text box so that i can do some validation .
This is what i have in the validate() function .


var a1=document.form1.elements[1].value;
var a2=a1+'';
var a3=a2.split(",");
alert(a3[0]+a3[1]);

I'm able to read only a3[0] and not a3[1] .
But if i submit this to the next ASP Page i'm able to read everything but not in the same ASP Page in javascript function .
Please let me know where i'm doing wrong .

glenngv
05-31-2004, 06:26 AM
Accessing a3[1] will produce an error if the value of the textbox has no comma. What kind of validation are you trying to do?

laker_66
05-31-2004, 01:43 PM
I'm trying to validate to see if the user enetered any special charcters in the Input text box .Also validating if the input box is empty .All i wanted to do is loop inside the array of document.form1.elements[1].value

glenngv
06-01-2004, 04:54 AM
Start with this:


<script type="text/javascript">
function validate(f){
var nms = f.NM;
for (i=0;i<nms.length;i++){
if (nms[i].value=='') {
alert("Empty!");
nms[i].focus();
return false;
}
//other validations here
}
return true;
}
</script>

<form name="form1" method="POST" action="sasd.asp" onsubmit="return validate(this);">
<%
for(i=0;i <3;i++)
{
%>
<input type="text" name="NM" style="width:150px" />
<%
}
%>
<input type="submit" name="btnSubmit" />
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum