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
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
Try using jquery focus like
$("#id2").focus();
You can use
var i = 0 //or 1,2,3
document.getElementsByName('dropname['+i+']')[0].focus();
hope this will help you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With