1 Replies - 1239 Views - Last Post: 26 May 2014 - 12:02 PM Rate Topic: -----

#1 sheketo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-April 14

use jquery to select a dropdown option on button click control

Posted 19 May 2014 - 04:41 AM

I want to use jQuery to select an option, say the 3th item, in a DropDownList by clicking a button, then have the DropDownList box change it's value, say '44'.


<title></title>
<script type="text/javascript" src="Javascripts/jquery-1.4.1.js"> </script>
<script type="text/javascript">
$('#MyButton').click(function () {
$('#DropDownList2').val("3");;
});
</script>

<asp:DropDownList ID="DropDownList2" runat="server" ClientIDMode="Static"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem Selected="True">SELECT</asp:ListItem>
<asp:ListItem Value="1">23</asp:ListItem>
<asp:ListItem Value="2">32</asp:ListItem>
<asp:ListItem Value="3">44</asp:ListItem>
<asp:ListItem Value="4">61</asp:ListItem>
</asp:DropDownList>

<asp:Button ID="MyButton" runat="server" Text="MAX" />

Is This A Good Question/Topic? 0
  • +

Replies To: use jquery to select a dropdown option on button click control

#2 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,505
  • Joined: 16-March 11

Re: use jquery to select a dropdown option on button click control

Posted 26 May 2014 - 12:02 PM

View Postsheketo, on 19 May 2014 - 05:41 AM, said:

I want to use jQuery to select an option, say the 3th item, in a DropDownList by clicking a button, then have the DropDownList box change it's value, say '44'.


<title></title>
<script type="text/javascript" src="Javascripts/jquery-1.4.1.js"> </script>
<script type="text/javascript">
$('#MyButton').click(function () {
$('#DropDownList2').val("3");;
});
</script>

<asp:DropDownList ID="DropDownList2" runat="server" ClientIDMode="Static"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem Selected="True">SELECT</asp:ListItem>
<asp:ListItem Value="1">23</asp:ListItem>
<asp:ListItem Value="2">32</asp:ListItem>
<asp:ListItem Value="3">44</asp:ListItem>
<asp:ListItem Value="4">61</asp:ListItem>
</asp:DropDownList>

<asp:Button ID="MyButton" runat="server" Text="MAX" />


I believe you'll have to use the :eq selector. Should be something along the lines of $('#DropDownList2:eq(3)').val("whatever you want in here");
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1