www.webdeveloper.com
Results 1 to 4 of 4

Thread: Catch Index number of form element array

  1. #1
    Join Date
    Jan 2010
    Posts
    41

    Catch Index number of form element array

    hi,

    I want to get index number of form element array. where I want to put name in the front of code input box. Can any body tell me that how is possible.

    My code is as follow:

    PHP Code:
    <?php 

             
    echo "<form name="region">"
             
            for (
    $i=1;$i<=5;$i++){ 
            echo 
    '<input type="text" name="code[]"  onkeyDown="check(this)"> 
    '

            echo 
    '<input type="text" name="name[]"  > 
    '
    ;         

            } 
            echo 
    '<form>';  

    ?>
    and JS FILE is

    Code:
    function check(k){
          
          var name=document.region.elements("name[]");
          
          name[k.index]="London";
    
         }

    I tried to use this code but it does not work

  2. #2
    Join Date
    Aug 2007
    Posts
    3,767
    What exactly are you trying to do? Though I suspect that using k.value instead of k.index is the solution you're looking for.
    Great wit and madness are near allied, and fine a line their bounds divide.

  3. #3
    Join Date
    Jan 2010
    Posts
    41
    Actually I need the index Number of k which I want to use for the next column like name
    Hope you will be understand

  4. #4
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Hi Rashid,

    There is no property of a form element that indicates its order in the DOM. Since such a value isn't readily available, you'll have to calculate it for each element, which can be an expensive operation. Your alternative to that would be to cache the initial calculation and reference it later, reducing your iterations (but not the processing time of the initial).
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles