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 Wanet Telecoms Ltd 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 1

Status
Not open for further replies.

spirit66

Technical User
Apr 10, 2004
29
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 .
 
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>

function validate()
{
 var objs=document.getElementsByName("NM");
 //now objs contains all the inputs named "NM"
 for(i=0;i<objs.length;i++)
  alert(objs[i].value)
 return false
}

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top