Created
November 13, 2009 18:12
-
-
Save DoubleBrotherProgrammer/234041 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Helper function to select a text value in a <select> | |
If the value doesn't exist, selectedIndex = 0 | |
*/ | |
function selectedValue(menu_id, value) | |
{ | |
// get menu | |
var c_menu = document.getElementById(menu_id); | |
if( c_menu ) | |
{ | |
var option_ct = c_menu.options.length; | |
// marker used to let us know if we found value | |
var found_val = false; | |
for (var xx = 0; xx <= option_ct - 1; xx++) | |
{ | |
if (value == c_menu.options[xx].text.toLowerCase()) | |
{ | |
found_val = true; | |
c_menu.selectedIndex = xx; | |
} | |
// get out of loop if we already found value | |
if( found_val ) break; | |
} | |
// did we find the val? | |
if( ! found_val ) | |
{ | |
// NO | |
c_menu.selectedIndex = 0; | |
} | |
} | |
else | |
{ | |
alert("Invalid menu id : " + menu_id ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment