Hang on...

jQuery Change select dropdown value and remove selected attribute

Share |
Again, this is just a quick note about how to select an option with jQuery and remove the selected attribute.

$("#id-select :selected").removeAttr("selected");
$('#id-select').val('[value you need to select]');

As you can see, it is not enough just to select a new value using .val() because the selected attribute will stay on the form item and when you submit the form, the old value will be used.

Comments

Thanks. Simple and Precise

Thanks.
Simple and Precise

Thanks a lot

Thanks a lot

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <caption> <tbody> <tr> <td> <em> <b> <u> <i> <strong> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <param> <strike>
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].

More information about formatting options