Two common tasks using jQuery

In this post we will take a look on how to perform two common tasks using jQuery . We will see how following tasks can be performed,

  1. Reading and setting text of label
  2. Reading value of selected item from drop down

Reading and setting text of label

Let us say you have label on HTML as following,


<label id="locationbox"> </label>

You can read value as following ,


var valueoflabel = $('#locationbox').text();

You can set text in label as following,


$('#locationbox').text("MyText");

Reading value of selected item from drop down

Let us say you have drop down as following on html,


<select id="typeofreport">
<option value="Rape">Rape</option>
<option value="EveTeasing">Eve Teasing</option>
<option value="Molestation">Molestation</option>
<option value="VerbalAbuse">Verbal Abuse</option>
<option value="Harassmentatwork">Harassment at work</option>

</select>

You can read text of selected value of drop down as following ,


var typeofincident = $("#typeofreport option:selected").text();

These are the two tasks I wanted to share with you. I hope you find this small blog post useful. Thanks for reading.

About these ads

One thought on “Two common tasks using jQuery

  1. Pingback: Dew Drop – January 7, 2013 (#1,476) | Alvin Ashcraft's Morning Dew

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