Jquery - how to set a select value

Posted on 2014-08-16
Last Modified: 2014-08-16
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>
Question by:JElster
    LVL 42

    Accepted Solution


    $(function() {

    Open in new window

    <!DOCTYPE html>
    <script src="//"></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

    LVL 1

    Author Closing Comment

    thx again
    LVL 42

    Expert Comment

    by:Rob Jurd, EE MVE
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    by Julian Matz As of jQuery ( 1.4 the .live() method ( supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
    Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now