Thursday, 15 July 2010

jquery - store and duplicate input changing id x times -



jquery - store and duplicate input changing id x times -

hi guys wounder best way accomplish this:

i have input element within hidden field div. on page load input id='upload_logo', generate x amount of times , append to same div updating name , id 1 each time .

<div id="hidden_fields"> <input type='hidden' class='hidden' name='upload_logo' id='upload_logo' value='filepath/filename.eps'/> </div

this generate:

<div id="hidden_fields"> <input type='hidden' class='hidden' name='upload_logo' id='upload_logo' value='filepath/filename.eps'/> <input class="hidden" type="hidden" id="upload_logo_x" name="upload_logo_x" value="filepath/filename.eps" > <input class="hidden" type="hidden" id="upload_logo_x" name="upload_logo_x" value="filepath/filename.eps" > <input class="hidden" type="hidden" id="upload_logo_x" name="upload_logo_x" value="filepath/filename.eps" > </div

you can utilize for loop this. here hidden_fields #hidden_fields element, upload_logo #upload_logo element , number number of elements want generate.

var hidden_fields = $('#hidden_fields'), upload_logo = $('#upload_logo'), number = 3; (var = 0; < 3; i++) $('<input />', { type: 'hidden', 'class': 'hidden', id: 'upload_logo_' + i, name: 'upload_logo_' + i, value: upload_logo.val() }).appendto(hidden_fields);

jsfiddle demo.

as fields hidden, here screenshot of generated:

jquery html

No comments:

Post a Comment