<html>
<head>
<script type="text/javascript">
function getIndex()
{
var x=document.getElementById("mySelect");
if (x.selectedIndex == 2);
{
alert("correct");
}
else
{
alert("incorrect");
}
}
</script>
</head>
<body>
<form>
Select your favorite fruit:
<select id="mySelect">
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>
<input type=submit value="Go" onclick="getIndex()">
</form>
</body>
</html>
Drop down if..else not working.
Started by Nemesis4895, Oct 26 2010 02:02 PM
5 replies to this topic
#1
Posted 26 October 2010 - 02:02 PM
Hey, I'm new to this site and new to programming in general. Working on basics of javascript currently. Below is the script I'm working on, but its not working. The code looks right to me, but obviously it's wrong. Point me in the right direction please?
|
|
|
#2
Posted 26 October 2010 - 02:14 PM
Are you using IE? I copied the script and tried it in Firefox and it works fine.
#3
Posted 26 October 2010 - 02:16 PM
Nope, I'm using the latest version of firefox. Whenever I click submit, it just refreshes the page.
#4
Posted 26 October 2010 - 02:30 PM
Ahh ok I got you now...yea it does that on mine also...hmm i'll look more into it
#5
Posted 26 October 2010 - 02:45 PM
Alright, thanks.
#6
Posted 27 October 2010 - 07:00 AM
It has an incorrect ';' after the if-line.
if (x.selectedIndex == 2)[COLOR="red"][SIZE="5"];[/SIZE][/COLOR]


Sign In
Create Account

Back to top









