Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-30-2010, 07:20 PM   PM User | #1
johnmerlino
Regular Coder

 
Join Date: Oct 2009
Posts: 189
Thanks: 38
Thanked 3 Times in 3 Posts
johnmerlino is an unknown quantity at this point
val() method of jquery

Hey all,

let's say this.filter_id refers to the select element below, which has three options:
Code:
<select id="filter_1">
<option value="0">Filter:</option>
<option value="2009-10-01">2009-10-01</option>
<option value="2009-11-20">2009-11-20</option>
</select>
var filter_value = jQuery(this.filter_id).val();
In this case, is the val() method returning the value (0) of the first option element or does it return the value of the collection of option elements as an array?

jQuery help page says this:
Get the current value of the first element in the set of matched elements.

Thanks for any response.
johnmerlino is offline   Reply With Quote
Old 06-30-2010, 09:04 PM   PM User | #2
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
The "first element in the set of matched elements" is the first select (or any other input) matched by the selectors used. In your case, the set is just one element, so the val() is the value of that element - whatever is selected.

You can examine the operation with a simple example:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$('#filter_1').change(function(){
		alert($(this).val());
	});
});
</script>
</head>
<body>
<select id="filter_1">
<option value="0">Filter:</option>
<option value="2009-10-01">2009-10-01</option>
<option value="2009-11-20">2009-11-20</option>
</select>
</body>
</html>
__________________
Are you a Help Vampire?
tomws is offline   Reply With Quote
Reply

Bookmarks

Tags
filter, jquery, option, select, val

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:37 PM.


Advertisement
Log in to turn off these ads.