0

I want to select options dynamically in a html select element by Jquery or JavaScript. Is there any way for this.So, as soon as i select it , it will select as well as trigger the onchange event handler.

Thanks in Advance.

2
  • Do you have any code? Commented Mar 14, 2013 at 7:25
  • <select><option value='1'>sun</option><option value='2'>moon</option><option value='3'>star</option></select>.Now i want to select the moon option in javascript or jquery dynamically Commented Mar 14, 2013 at 8:18

1 Answer 1

1

You can set the value using .val("new value"), and trigger the jQuery event handlers for the change event via .change(), e.g.:

$("selector for the select box").val("new value").change();
Sign up to request clarification or add additional context in comments.

3 Comments

I am using $('#yourselectID').val(value).trigger('onchange'); It's working fine..Thanks.
@mns: That should be .trigger('change'), but yes, that's just the long-hand way of writing .change().
.change() is just changing the value not triggering the event , if u have a working example can u pls share here the same

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.