This is my original code to create an input field:
$('#dynamicForm').append('<li id="pdport"></li>');
$('#pdport').append("<label for='sport'>Destination port</label>")
$('<input>').attr({type: 'text', id: 'dport', name: 'dport'}).appendTo('#pdport');
$('#pdport').append("<span>Enter the destination port here (0-65535)</span>");
Instead of doing this code over and over I'm trying to create a function for it
function createInputfield(mainID, childID, labelFor, labelText, spanText){
$(mainID).append('<li id=childID></li>');
$(childID).append("<label for=labelFor>labelText</label>")
$('<input>').attr({type: 'text', id: labelFor, name: labelFor}).appendTo(childID);
$(childID).append("<span>spanText</span>");
}
and than calling to function with
createInputfield("#dynamicForm", "#psport", "sport", "Source port", "Enter the source port here (0-65535)");
this way I can create a lot of dynamic input fields without copy/pasting a lot of the same code.
The problem is that this doesn't work, I always get syntax errors, like you can't append on mainID and others. I tried a lot of different ways to accomplish this like with quotes, with single quotes, without.. But nothing seems to work.