Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
72
rated 0 times [  75] [ 3]  / answers: 1 / hits: 5300  / 11 Years ago, wed, january 1, 2014, 12:00:00

I am sending the index number of dropdown's options that users selects from index. Now want to select that specific option as 'selected' on another view. How to make it using jQuery?



$('#book_selection').attr(disabled, disabled);
$('#book_selection').selectedIndex = 1;


but its not working...


More From » jquery

 Answers
1

Use prop() method, setting selectedIndex to a jQuery object practically does nothing. As of jQuery 1.6 for modifying properties prop method should be used instead of attr method:



$('#book_selection').prop(disabled, true)
.prop('selectedIndex', 1);


Alternatives:



// Getting the DOM element object using bracket notation and `.get()` method
$('#book_selection')[0].selectedIndex = 1;
$('#book_selection').get(0).selectedIndex = 1;

[#49088] Tuesday, December 31, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jenamackennac

Total Points: 304
Total Questions: 110
Total Answers: 107

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
jenamackennac questions
Fri, Feb 18, 22, 00:00, 2 Years ago
Wed, Apr 21, 21, 00:00, 3 Years ago
Thu, Apr 1, 21, 00:00, 3 Years ago
Tue, Feb 2, 21, 00:00, 3 Years ago
;