Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
99
rated 0 times [  100] [ 1]  / answers: 1 / hits: 41441  / 11 Years ago, tue, october 1, 2013, 12:00:00

I have a no of dropdown list as follows



<select name=dropname[0]>....</select>
<select name=dropname[1]>....</select>
<select name=dropname[2]>....</select>
<select name=dropname[3]>....</select>....


Now I want to set focus on second drop down list.I tried these



document.getElementsByName('dropname')[1].focus();


results this error



TypeError: document.getElementsByName(...)[1] is undefined


Thanks in advance


More From » jquery

 Answers
43

Since you tagged your question with jQuery, try something like



$('select[name^=dropname]').eq(1).focus();

// $('select[name^=dropname]') < elements whos name starts with dropname
// .eq(1) < select one based on its index
// .focus(); < use jQuery's focus method to set the focus

[#75305] Monday, September 30, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tylerdamiena

Total Points: 139
Total Questions: 90
Total Answers: 118

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
tylerdamiena questions
;