Click to See Complete Forum and Search --> : null or not an object error


Happy Anorak
06-29-2003, 09:47 AM
I'm a complete novice with this so apologies if I'm missing or not doing something really obvious. I'm trying to incorporate a pull down menu that automatically jumps to any selection into a php generated page. However I get the following error message when I try to run the script:

form is null or not an object

Can anyone help pse. here's the code I'm trying to incorporate:

<!-- STEP ONE: Copy this code into the HEAD of your HTML document -->

<HEAD>

<SCRIPT LANGUAGE="JavaScript">

<!-- Original: Alex Tu <boudha1@hotmail.com> -->
<!-- Web Site: http://www.geocities.com/MadisonAvenue/4368 -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function formHandler(form){
var URL = document.form.site.options[document.form.site.selectedIndex].value;
window.location.href = URL;
}
// End -->
</SCRIPT>
</HEAD>

<!-- STEP TWO: Paste this code into the BODY of your HTML document -->

<BODY>

<center>
<form name="form">
<select name="site" size=1 onChange="javascript:formHandler()">
<option value="">Go to....
<option value="http://www.yahoo.com">Yahoo
<option value="http://www.metacrawler.com">Metacrawler
<option value="http://www.altavista.digital.com">Altavista
<option value="http://www.webcrawler.com">Webcrawler
<option value="http://www.lycos.com">Lycos
<option value="http://javascript.internet.com">JavaScript Source
</select>
</form>
</center>

pyro
06-29-2003, 10:11 AM
Change:
<select name="site" size=1 onChange="java script:formHandler()">
to:
<select name="site" size=1 onchange="formHandler();">

Charles
06-29-2003, 11:30 AM
As I abhor web pages that rely upon JavaScript I wouldn't normally do this, but then that JavaScript is so bad that I feel the need to demonstrate the proper method. This is just for demonstration purposes. Do not employ navigation that relies upon JavaScript.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>An Example of an Abhorrent Technique</title>
<select size=1 onchange="top.location = this.value">
<option value="">Go to....
<option value="http://www.yahoo.com">Yahoo
<option value="http://www.metacrawler.com">Metacrawler
<option value="http://www.altavista.digital.com">Altavista
<option value="http://www.webcrawler.com">Webcrawler
<option value="http://www.lycos.com">Lycos
<option value="http://javascript.internet.com">JavaScript Source
</select>

Happy Anorak
06-29-2003, 01:12 PM
Thanks guy's, I have it working, sort of.