select value of 2 html select element witht the jquery

I have a situation where i have to select the dropdown value like this

$(this).parent().parent('div').find('option:selected').val();

later i realized that i need to put 2nd ddl there in the same div, so now i become confuse how to fetch the value of each of this DDL. is there a way to apply id for this code

$(this).parent().parent('div').find('option:selected').val();

so that i can fetch each.

following is my code this is first ddl.

<select style="width:30px" name="ddlQty" id="ddlQty" class="positive-integer"><option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>

and this is second

<select name="OptionID" id="OptionID"><option value="14">5''  £25.00</option>
</select>

how can i select each of this value?

Answers


For the fisrt one:

$(this).parent().parent('div').find('#ddlQty option:selected').val();

And the second one:

$(this).parent().parent('div').find('#OptionID option:selected').val();

If Id's are unique as it should

$('#ddlQty').val();

and

$('#OptionID').val();

$('#ddlQty').val();
$('#OptionID').val();

would get the value of each select menu.


IDs should be unique, so you shouldn't need the $(this).parent().parent('div') part. The following should work

$('#ddlQty').val();
$('#OptionID').val();

Need Your Help

What is the necessity of DAO Architecture

java asp.net design-patterns dao

When programming in Java is it always necessary to code according to the DAO architecture? If so what are advantages of using it? I'm doing a project which has a class diagram like below. what are...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.