im having a problem with dynamic forms.
I have dynamically created forms on button “add”. forms have ids like “editForm_1”.
for example, i have an input “Education_1” and the select box that will be filled on input click and options will be based on input value. having like 5 of those input fields and selects.
the thing is that how can i manage all those events? cause i dont think .each input is a good solution.
thanks
UPD:
$("#education").delegate("input", "keypress", function(){
if($(this).val().length>1){
var selector = $(this).next();
selector.empty() ;
var words = $(this).val();
$.postJSON("2.php", words, function(data){
var tmp = data;
$.each(tmp, function(i, val){
var s=selector;
s.options[s.options.length]= new Option(val.type, val.type);
});
});
}
});
But im getting “s.options is undefined” ERROR
got it, used
s.append( new Option(val.type, val.type));
instead and it works
Instead of attaching events using their ID’s, group the inputs into classes, then attache the event handler(s) using
.delegateor.onfor these classes.e.g
The js