0

How to select dropdown option at the time of document load using Jquery?

3 Answers 3

2

Use

$(document).ready(function(){

$('#select-Id').val("rightVal");

});

Example: For

<select id='days'>
<option value="sun">Sunday</option>
<option value="mon">Monday</option>
</select>

Use below code to select Monday

$(document).ready(function(){

$('#days').val("mon");

});
Sign up to request clarification or add additional context in comments.

Comments

1

HTML:

<select id="sel">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

Jquery:

$(document)​.ready(function(){


    $('#sel').val('2');


    })​;​

See Demo

Comments

1

You can use

$(document).ready(function(){
   $('#sel').val('myValue'); // to set the current value
   var selectedvalue=$('#selectId').val(); // get the selected value
   alert(selectedvalue); 
});

DEMO.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.