Add new input field dynamically
- Single Page
Posted 19 November 2012 - 10:42 AM
I would like to have next to my input field a button that when a user click, it will create a new input field on each click. User can supply information on each field and will be saved to DB when the user click the save button. I saw several example of add/remove textbox dynamically using jQuery but I would like to know if there is a native way in GC in doing this? If possible without tweaking core GC codes.
Here's how my current field looks like. If I click "Add new ITR" button I'd like to see new input field/s to be created below it.
[attachment=363:dynamic.JPG]
Thanks and BR,
clustersblue
Posted 23 November 2012 - 05:07 AM
[attachment=372:addremove.JPG]
I'm currently tracing my code right now and it's been awhile that I'm doing this. I'll update this post as soon as I got this right, for now here is my code in case someone is interested to see:
var i = $('#issues_list_input_box p').size() + 1;
$(document).on('click','#add_itr',function() {
$('<p><label for="issues_list_input_box"><input type="text" id="p_scnt" size="10" maxlength="10" name="dynamic[]" placeholder="Input ITR" value=""/></label><img src="../../../assets/resources/img/icon/close.png" id="rem_itr" alt="remove"></img></p>').appendTo('#issues_list_input_box');
i++;
return false;
});
$(document).on('click','#rem_itr',function() {
if( i > 2 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
Posted 23 January 2013 - 10:08 AM
$('#add_itr').on('click',function() {
$('<p><label for="p_scnts"><input type="text" id="p_scnt" size="10" maxlength="10" name="dynamic[]" placeholder="Input ITR" value=""/></label><img src="../../../assets/resources/img/icon/close.png" id="rem_itr" alt="remove"></img></p>').appendTo('#issues_list_input_box');
i++;
return false;
});
$('#issues_list_input_box').delegate("img","click",function(event) {
event.preventDefault();
if( i > 1 ) {
$(this).parents('p').remove();
i--;
}
return false;
});
Posted 09 April 2013 - 03:28 AM
hi clustersblue,
same with the ts problem, how i change my code with your code???
thanks
Posted 13 June 2018 - 20:05 PM
Mark!