Jump to content

selecting option with jquery


Recommended Posts

I have tried with various ways to make a selection of an option from a dropdown menu using jquery.

Here is the menu:

   <select class="dropdown">                          <option value="08:00">08:00</option>                          <option value="08:30">08:30</option>                          <option value="09:00">09:00</option>                          <option value="09:30">09:30</option>                          <option value="10:00">10:00</option>   </select>

I have tried various js codes but I cannot make it work-here is what I have tried:

$(".dropdown").prop("selected","08:30");$( ".dropdown" ).attr("selected","08:30");$(".dropdown option[value=08:30]").prop("selected");

I am trying to set(for example) the option to 08:30

Link to post
Share on other sites

Here is the solution to it

 $('.dropdown').val('09:30');//09:30 is just an example, it could be anything
Edited by jimfog
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...