jquery - Set focus on dropdown by select name with variable -
jquery - Set focus on dropdown by select name with variable -
i'm trying set focus of dropdown using variable in select name=+variable+ alert shows right name of select focus on focus doesn't set. if utilize actual name of select instead of variable focus works. i've looked @ several examples , tried mix of putting in " around name still won't focus. looking.
css
<style> select:focus { background-color: yellow; } </style>
jquery
<script> $('input[name^=dialsetting]').click(function () { var name = $(this).attr('name'); var headtypenum = name.replace('dialsetting', 'headtype'); alert(headtypenum); $('select[name=+headtypenum+]').focus(); }); </script>
html
<select name="headtype1"> <option id="item37_0_option" selected value="1">choose one</option> <option id="item37_1_option" value="a3">a3</option> </select> <br> <br> <select name="headtype2"> <option selected value="1">choose one</option> <option value="a4">a4</option> </select> <br> <br> <input name="dialsetting1" required type="number" /> <br> <br> <input name="dialsetting2" required type="number" />
here's fiddle http://jsfiddle.net/progrower/3k4jv275/1/
you selector wrong. alter to:
$('select[name=' + headtypenum + ']').focus();
demo
jquery
Comments
Post a Comment