Javascript: Help a n00b in distress!

Bes

Bes

Soldato
Joined
18 Oct 2002
Posts
7,318
Location
Melbourne
Hi

I have a page (it is actually an rrd-cgi based page) where I want to process 2 different sets of code based on a user's selection from a combo box.

How can I do this in javascript? I need something like

<select name="example" size="1" onChange="content=this.options[this.selectedIndex].value">

<option value="1">one</option>
<option value="2">two</option>

if content=1 then <Do this code>
else <do that code>

How can I do this? I cannot seem to get anything to work

Thanks
 
Code:
<script type="text/javascript">
//<!--
function ProcessSelection()
{
	var selectedOption = combo.options[combo.selectedIndex].text;
	
	if (selectedOption == "one")
	{
		// Do something 	
	}
	else if (selectedOption == "two")
	{
		// Do something else
	}
}
//-->
</script>


<body>

<select id="combo" name="example" size="1" onchange="ProcessSelection();">
	<option value="1">one</option>
	<option value="2">two</option>
</select>

</body>
 
Code:
<html>
<body>

<select id="combo" name="example" size="1">
    <option value="1">one</option>
    <option value="2">two</option>
</select>

</body>


<script type="text/javascript">
//<!--
    document.getElementById("combo").onchange = function () {
        var value = this[this.selectedIndex].value;
        
        switch (value) {
            case "1" : {
                alert("case1");
                break;
            }
            case "2" : {
                alert("case2");
                break;
            }
        }
    }
//-->
</script>

</html>
 
Back
Top Bottom