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

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -