• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

Jquery - how to set a select value

Hi.. again
I have the following, how can I set the 'selected' value in JQuery...  for example I need the selected value to be '1.0'

 <select name="errorcodeedit" id="ErrorCodeEdit" style="width: 450px;">
                                  strSql = " SELECT error_code, error_description FROM eps.error_codes order by error_code "
                                  rs3.Open strSql, connection
                                  <option value=''>Select</option>
                                  Do Until rs3.EOF
                                        <option value='<%=rs3.Fields(0).Value%>'><%=rs3.Fields(0).Value%>&nbsp;-&nbsp<%=rs3.Fields(1).Value%></option>
  • 2
1 Solution
RobOwner (Aidellio)Commented:

$(function() {

Open in new window

<!DOCTYPE html>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
<select id='ErrorCodeEdit'>
	<option value="0">--select--</option>
	<option value="1.0">one point zero</option>
	<option value="2.0">two</option>
	<option value="3.0">three</option>

Open in new window

JElsterAuthor Commented:
thx again
RobOwner (Aidellio)Commented:
No problem. I also wanted to mention you could add the selected attribute to the relevant option tag as you were outputting it. It just depends on when you want that option selected.
If it's before the user had interacted with the page then it may be better to put in the selected attribute as you're outputting the code on the server side.
If you're going to bed to select that option because of another action the user does, well it's best left in the JavaScript

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now