Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Input text box in FOR LOOP with same Name

    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 .

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    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?

  • #3
    New to the CF scene
    Join Date
    May 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Start with this:
    Code:
    <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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •