Revision: 52770
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 1, 2011 15:08 by jackkeller
Initial Code
$(document).ready(function() { $('#forms').css({'border': '1px solid #333333', 'padding': '10px'}); var forms = ["tname", "temail", "tphone", "sinquiry", "amessage"], index; var form = $('#forms'); for (index = 0; index < forms.length; index++) { var indextype = forms[index].substring(0,1); var indexname = forms[index].substring(1); form.append('<label for="'+indexname+'">'+indexname+'</label>\n'); switch(indextype) { case "t": form.append('<input type="text" name="'+indexname+'" id="'+indexname+'" />\n\n'); break; case "s": form.append('<select name="'+indexname+'" id="'+indexname+'">\n\t<option></option>\n\t<option></option>\n</select>\n\n'); break; case "a": form.append('<textarea name="'+indexname+'" id="'+indexname+'"></textarea>\n\n'); break; } } var output = $('#forms').html(); output = output.replace(/</g,'<',output); output = output.replace(/>/g,'>',output); output = output.replace(/\n/g,'<br />',output); output = output.replace(/\t/g,' ',output); $('#theform').html(output); });
Initial URL
Initial Description
Initial Title
jQuery Form from Array
Initial Tags
jquery
Initial Language
JavaScript