jQuery Getting Value and Text from Select Tag

I often forget this code so here it goes. Here’s the jQuery part:

$('#firstSelect').live('change', function(){
val = jQuery(jQuery('#firstSelect').find(":selected")).html();
alert(val);
});

while here’s the HTML part:

<select onchange="" name="attributes" id="firstSelect">
<option value="">Color/Finish</option>
<option value="4294860237">Black</option>
<option value="4294860179">Gray</option>
<option value="4294860020">Beige</option>
<option value="4294860011">Charcoal</option>
<option value="4294858068">Tan</option>
<option value="4294857128">Camel</option>
<option value="4294851209">Khaki</option>
<option value="4294851194">Medium stone</option>
<option value="4294851193">Slate gray</option>
<option value="4294851192">Dark slate</option>
<option value="4294851190">Dark khaki</option>
<option value="4294851189">Taupe and khaki</option>
<option value="4294843384">Cashmere</option>
</select>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s