/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(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); });