| Javascript Dropdownlist Loop |
|
Here is the code for how you can loop around the drop down list and do certain things in javascript. In this code what it does is to loop around the each item in the dropdownlist and it check to see if a particalur item is selected and if it is it will alert a message box. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript"><!--
function ValidateUtilityList(object) { var obj = null;
if("string"==typeof(object)) obj = document.getElementById(object); else obj = object
for(var i=0; i < obj.options.length; i++) { if(obj.options[i].selected) { alert(obj.options[i].value + " " + obj.options[i].text); } } }
//--></script> </head> <body> <form> <select id="sgGeneral_chkUtilityShut" onchange="ValidateUtilityList(this)"> <option value="1">Pump</option> <option value="2">Power Generator</option> <option value="3">Pipeline</option> </select>
<input type="button" onclick="ValidateUtilityList('sgGeneral_chkUtilityShut')" value="show value"/> </form> </body> </html>
|