SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Manchester
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting the name of the field that has had its value changed

    Hi guys,

    I have a input field array, and have associated a change JQuery event handler if the value of any of the fields in the array have changed. So:

    PHP Code:
    <input type='text' name='field[0]'>
    <
    input type='text' name='field[1]'
    and..

    PHP Code:
    $("[id^=field]").change(function() {
      
    // do action here

    In the Javascript, how can I retrieve the name (or index to be more precise) of the field that has had its value changed?

    Many thanks.

  2. #2
    SitePoint Addict
    Join Date
    Apr 2007
    Posts
    300
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $("[id^=field]").change(function() {
    
    var index = $('input').index(this);
    
    }

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Manchester
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Beautiful. Figured it would be something very simple indeed. Much thanks!


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
  •