Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a null or not an object error (info not found in faqs)

Status
Not open for further replies.

TinMan486

Programmer
Jul 14, 2008
8
US
I am trying to link to a site based on a selection made in a pull down menu. The script is fundamentally simple but for some reason it will not execute.
Code:
<html>
<head>
</head>
<body>
<script type='text/javascript' 
                
        function Navigator(nav.selectURL.value)
        {
        document.location.href=document.nav.SelectURL.options[document.nav.SelectURL.selectedIndex].value
        }
</script>
<form> 
Select A Report:<br>
<FORM NAME="nav" id="nav"><DIV>
<SELECT NAME="SelectURL" onChange="Navigator(nav.selectURL.value)">
<OPTION VALUE="index.htm"
SELECTED>Please select an item:
<OPTION VALUE="websiteiwanttolinksurl">
Fire Reports
</SELECT><DIV>
</FORM>
</body>
</html>

I am not sure if the error is with passing the data to the function or if the function is even working properly... any help would be appreciated.
 
javascript is case-sensitive. this:
Code:
<SELECT NAME="SelectURL" onChange="Navigator(nav.selectURL.value)">
should be:
Code:
<SELECT NAME="SelectURL" onChange="Navigator(nav.SelectURL.value)">

you might run into cross-browser issues with some browsers not reporting the select's selected option when accessed via "SelectURL.value" - a safer way would be
Code:
<SELECT NAME="SelectURL" onChange="Navigator(nav.SelectURL.options[nav.SelectURL.selectedIndex].value)">
you could also use the "this" keyword to refer to the object that the event handler is attached to, further condensing the script:
Code:
<SELECT NAME="SelectURL" onChange="Navigator(this.options[this.selectedIndex].value)">
one more thing, your function definition of Navigator has a syntax error in the argument "nav.selectURL.value" - dots are not allowed in argument names. you're also never using the argument. the function could be rewritten as such to use the argument:
Code:
        function Navigator(URL)
        {
        document.location.href = URL;
        }

-jeff
lost: one sig, last seen here.
 
Along the same vein, say I wanted to do something like, change the text inside of a DIV or load a page into A div on my original page... Could i just say

Code:
<body>
<script type='text/javascript'>
        
        function Navigator(URL)
        {

          document.getElementById(reportspace).innerhtml = 'this is working';
        }
</script>

<form> 
Select A Report:<br>
<FORM NAME="nav" id="nav">
<SELECT NAME="SelectURL" onChange="Navigator(this.options[this.selectedIndex].value)">
<OPTION VALUE="index.htm" SELECTED>Please select an item:
<OPTION VALUE="url">
Report1
<OPTION VALUE="url">
Report2

</FORM>
<div id="reportspace"><b>Report info will be listed here.</b></div>

</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top