Results 1 to 2 of 2

Thread: Problem with getting the input values into javascript

  1. #1
    Join Date
    Sep 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Problem with getting the input values into javascript

    Hi All,

    I have a form with the input names as an array, i.e. the names of the form text boxes are input[0],input[1],input[2]....

    When I use the following i can get a single value

    form.elements['input[1]'].value

    I want all the values into the java script. I tried the code here and is not working. can you please tell me why?

    for(var i=0;i<=val1;i++)
    {
    val2='input['+i+']';alert(val2);
    alert(form.elements[val2].value)
    }


    I have to validate the user not entering the values into input[1] if input[0] is null and so on, but how do I get the all the values into the javascript. Please help me out.

    Thanks,
    Sowjanya.

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Code:
    for(var i=0; i<=document.frm.input.length; i++)
    {
         var val[i]= document.frm.input[i].value;
         alert(val[i]);
    }
    where

    Code:
    <form name="frm">
         <label>
              Field 1<input type="text" name="input[]" value="">
         </label>
         <label>
              Field 2<input type="text" name="input[]" value="">
         </label>
         <label>
              Field <input type="text" name="input[]" value="">
         </label>
    </form>

Bookmarks

Posting Permissions

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