Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input text box in FOR LOOP with same Name

Status
Not open for further replies.

laker67

Programmer
Jan 18, 2004
31
0
0
US
Hi,
I have a FORM which has a Input text box in a FOR loop .
Code:
<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 .
Code:
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 .
 
In that case form1.elements.NM becomes collection and you'll have to iterate through it ( => Javascript forum).

Btw. naming texboxes identically isn't best practice - it is usually OK only for radio/checbox stuff.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top