PDA

View Full Version : help with drop down javascript


mastahkaz
11-12-2002, 07:40 PM
OK, i need each select item to run a differnt javascript when selected. Here's what i used:


<html>
<head>

<script language="JavaScript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].name+"'");
if (restore) selObj.selectedIndex=0;
}

</script>

</head>

<body>

<select name="txtCapacity" onChange="MM_jumpMenu('self',this,0);">
<option selected value="0" name="#" >Select a lawn type ---></option>

<option value="890" id="single" name="javascript:fillList(0);">Single</option>

<option value="885" id="sing_sec" name="javascript:fillList(1);">Single & 2nd Right</option>

<option value="1730" id="second" name="javascript:fillList(2);">2nd Right Only *</option>
</select>

</body>
</html>


So what happens is when they pick one of those 3 options the javascript for that selection will kick in. Now it works fine, except in NS 6 & 7, after the javascript does its thing, it forwards to a non existant html page called ../undefined.

Anyone know how i can get this to work correctly in netscape?

kdjoergensen
11-13-2002, 05:15 PM
Your eval statement would produce following:

(example)

self.location = 'javascript:fillList(0)';

That, as you may have guessed, makes absolutely no sence. Why are you running a javascript command from the location object (no wonder the page is navigating away).

why not just:

eval(selObj.options[selObj.selectedIndex].name);

I can not see from your script what the fillList function does (or what values it returns), but if the intention is that the function will fill in another select element (for example) and then return a url which is being navigated to, then you can try:

var returnValue = eval(selObj.options[selObj.selectedIndex].name);
eval(targ+".location="+returnValue);

I think your problem is that you are using the location object for something it was not designed for.

mastahkaz
11-13-2002, 06:46 PM
sorry i forgot to post that i already figured this out yesterday.

Heres what ended up working for me:


<SCRIPT LANGUAGE=javascript>
// runs javascript based on what item is selected - burial spaces
function SubmitEvent() {
var nGetIndex = document.frmOne.txtCapacity.options[document.frmOne.txtCapacity.selectedIndex].id;
if (nGetIndex != 0)
{ javascript:fillList(nGetIndex);
}
}
</script>

kdjoergensen
11-14-2002, 09:19 AM
don't use javascript: inside script tags, simply call the function by it's name: fillList(0)