SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    971
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    jquery question about altering dynamically created form fields

    The link below is a stripped down section of a form.

    http://development.omprakash.org/test.html

    The problem I'm having is with altering the names of the fields. I'm trying to add an identifier on the end. "_X_1", "_X_2" after the new sections are added.

    NOTES:

    Incidentally, "_X_" is a delimiter so the key can be converted into an array on the back end to extract data from it.

    I can't alter the "repeater" variable because it would be extremely complicated on the back end.

    Thanks for your help,

    E

  2. #2
    SitePoint Guru
    Join Date
    Jan 2007
    Posts
    971
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I figured it out.

    The key was to use this selector "$('#cross_table_repeater').find(':input')"

    I don't understand why "$('input')" didn't register, but this did the trick.

    Code JavaScript:
    function adjust_names(){
     
        	$('#cross_table_repeater').find(':input').each(function(){
     
        	  identifier=$('div').index($(this).parent());
     
              old_name=$(this).attr('name');
              new_name=old_name+'_X_IDENTIFIER'+identifier;
              $(this).attr('name',new_name);
     
            });              
     
        }

    E


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
  •