Return to Snippet

Revision: 52770
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('&lt;label for="'+indexname+'"&gt;'+indexname+'&lt;/label&gt;\n');
		switch(indextype) {
			case "t":
		    	form.append('&lt;input type="text" name="'+indexname+'" id="'+indexname+'" /&gt;\n\n');
			break;
			case "s":
				form.append('&lt;select name="'+indexname+'" id="'+indexname+'"&gt;\n\t&lt;option&gt;&lt;/option&gt;\n\t&lt;option&gt;&lt;/option&gt;\n&lt;/select&gt;\n\n');
		    break;
			case "a":
				form.append('&lt;textarea name="'+indexname+'" id="'+indexname+'"&gt;&lt;/textarea&gt;\n\n');
		    break;
		}
	}
	var output = $('#forms').html();
	output = output.replace(/&lt;/g,'<',output);
	output = output.replace(/&gt;/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