Set value for Select – JavaScript
This JavaScript function allows you to set the value of a select tag without having to know its position in the list.
function setValueSelect(SelectName, Value) { SelectObject = document.getElementById(SelectName); for(index = 0; index < SelectObject.length; index++) { if(SelectObject[index].value.toLowerCase() == Value.toLowerCase()) SelectObject.selectedIndex = index; } }
Usage Example:
<select id="clang"> <option value="arabic">Arabic</option> <option value="english">English</option> <option value="french">French</option> <option value="persian">Persian</option> <option value="turkish">Turkish</option> </select>
setValueSelect("clang", "persian");
This selects the persian value in the select.
Related Posts- Open Classifieds 2.0 - Draft
- SEO Functions for PHP
- JavaScript to return dimensions
- Include Javascript file inside another
- Cache Class for PHP
- Best Index Funds: Does Vanguard Still Rule The Roost?
- The Source of Your Beliefs
- How to Determine Civil War Rare Coins Value
- Antique Lamps
Help sharing and Flatter me ;)
