Setting Input and Selects via JQuery

May 4th, 2012 by admin Leave a reply »

I thought I would post this quick little blurb about setting your HTML controls from JQuery. Here are the 2 lines that set those property types:

$("#id1").val("Your_String");
$('#id2').append($('<option>', { value: "Your_Value" }).text("Your_String");

And here is the complete Ajax call where I am setting those properties off the returned JSON:

function() {
            $.ajax({
                url: "http://www.yourdomain.com/data.json",
		        dataType: "jsonp",
		        success: function(parsed_json) {
			        var location = parsed_json['location']['city'];
                                $("#id1").val("Your_String");
                                $('#id2').append($('<option>', { value: "Your_Value" }).text("Your_String");
			      		        }
	        });
        }

Advertisement

Leave a Reply