#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    37
    Rep Power
    5

    Jquery to copy all hidden input fields and add them to a second form


    Currently I have about 15 hidden input fields that are created for a lead generation form. We are starting to test some new style forms in certain sections which are loading with ajax and I have that working just fine.

    Now what i want to do is grab all of the hidden input fields from form1 and append them with the same name and value to form2 which is on the same page.

    Code:
    	$("#form1 input[type=hidden]").each(function() {
    		 //alert($(this).val() + $(this).attr("name")); 
    
    		 $('form[name=form2]').append('<input type="hidden" name="'+ $(this).attr("name") + '" value="' + $(this).val() + '" />');
    	});
    That is the code and I know it is cycling through each hidden field from form1 as I got the alerts to show me it but nothing is getting appended to form2.

    Any help would be appreciated.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    37
    Rep Power
    5
    I figured it out. No need for a reply.
  4. #3
  5. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,122
    Rep Power
    4258
    Congratulations in figuring it out.

    These forums are a place for sharing information, so would you mind telling us what your solution was in case someone else has a similar problem in the future?
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo