...

View Full Version : Alert Box and Menu Help!!! AGH!



tomtimus
06-03-2004, 09:41 AM
Okay..i have the drop down menu...and I'm trying to make it so when you select "choose a genre" or "-------" an alert box pops up saying "please choose"...I'm 99.99% sure that my error is in the javascript part of the html...thnx for helping a beginner!



This is what I have:




<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Tom's Music Page</title>
<link rel="stylesheet" type="text/css" href="intro.css" />

<script language="Javascript">

function go()
{

if ( location=document.drop.mus.option[document.drop.mus.selectedIndex].asdf return

alert('Choose Again');
else
location=document.drop.mus.options[document.drop.mus.selectedIndex].value;
}


</script>
</head>

<body>

<h1>Choose A Genre!</h1>
</ br>
<img src="piano.jpg" width="502" alt="" />
<form name="drop">
<select name="mus" onChange="go()">
<option value="asdf">Choose a Genre!</option>
<option value="asdf">-------------</option>
<option value="page1.html">Hip-Hop</option>
<option value="page2.html">Alternative</option>
<option value="page3.html">Classical</option>
<option value="asdf">-------------</option>
<option value="index.html">Home!</option>
</select>



</form>

</body>
</html>

glenngv
06-03-2004, 10:06 AM
function go(objSelect)
{
var val = objSelect.options[objSelect.selectedIndex].value;
if (val=='asdf') {
alert('Choose Again');
}
else {
location.href=val;
}
}
...
<select name="mus" onChange="go(this)">

Using the this keyword simplifies the function. It doesn't need to know what the form name and select name are.

tomtimus
06-03-2004, 10:10 AM
OMGOMGOMGOMG You did it!!! THnx!!!!!!! I owe you!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum