dadamssg87 Posted October 3, 2011 Share Posted October 3, 2011 I'm trying to write an onclick function that appends a div with input fields in it to an existing div...if that makes sense. I suck at javascript though. I can't even append the div with one input field in it though. anybody any good with javascript? http://jsfiddle.net/XLuHU/1/ Link to comment https://forums.phpfreaks.com/topic/248364-dynamically-adding-form-input-fields/ Share on other sites More sharing options...
dadamssg87 Posted October 4, 2011 Author Share Posted October 4, 2011 got it function add_item( code, title, price, divbox ) { var idtag, item_title, item_price, item_code, separator; separator = " "; // Generate an id based on timestamp idtag = "div_" + new Date().getTime(); // Generate a new div. $( divbox ).append( "<div id=\"" + idtag + "\"></div>" ); if ( divbox == "#item_box1" ) { item_title = $("<input/>", { type: 'text', name: "box1_item_title[]", value: title }); item_price = $("<input/>", { type: 'text', name: "box1_item_price[]", value: price }); // Show in the document. $( "#" + idtag ).append( item_title, separator, item_price ); } else { item_code = $("<input/>", { type: 'text', name: "box2_item_code[]", value: code }); item_title = $("<input/>", { type: 'text', name: "box2_item_title[]", value: title }); // Show in the document. $( "#" + idtag ).append( item_code, separator, item_title ); } } Link to comment https://forums.phpfreaks.com/topic/248364-dynamically-adding-form-input-fields/#findComment-1275441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.