Hi,

First-timer here. Have JS that works in Safari, IE but not FF.
Very simple code:

<script>
function callFunction()
		{
if (eb.TobaccoProds.checked == true)
				{
					eb.action = "step2.php";
				}
			else
				{
					eb.action = "passthrough.php";
				}
				
			}
</script>
    <form id="eb" name="ebr" method="post" action="" onsubmit="return callFunction();">

When user clicks (or doesn't click) checkbox in form, the JS sends them to either page above.

FF error console tells me that eb is not defined.
eb isn't a var, so should not be defined.

Any help would be great, thx.

Put some argument inside your callFunction.

function callFuntion( eb ) {
// some statement.
}

now call it with your form onsubmit="return callFunction( this );"

If you want to make things shorter, try the following format in your document.

<html>
<head>
<title>Test Page</title>
<script type="text/javscript">
<!--

var callFunction;
   callFunction = function( eb ) {
   eb.action = (( eb.TobaccoProds.checked ) ? "step2.php" : "passthrough.php" );
};
//-->
</script>
</head>
<body>
<form id="eb" action="#" method="post" onsubmit="return callFunction( this );">
<div>
<input type="radio" id="TobaccoProds" name="TobaccoProds" value=""><br>
<input type="submit" value="submit">
</div>
</form>
</body>
</html>

Sorry. But my head screems when I see that code...

I'dd use something like this instead:

var callFunction = function(form)
{
    form.action = window.getElementById('TobaccoProds').checked ? "step2.php" : "passthrough.php";
}

But that's just the way I'm built.

If eb isn't a var, how on earth can you use it?

and if it was a var do you think i will use it? Everybody here apply appropriate help based on the capacity of the poster. Not by just showingOff your codes. And before you've posted it was already done. Tsk, tsk, tsk...

I'm not trying to show of. I'm just trying to help. Making sure the code is as browser-compliant as possible.

The only thing I changed was getElementById

You don't really get it don'tcha! All helped was based on the capacity of the poster it is ok to help as long as the code that you are posting is readable in their knowledge.

Because the script is placed before the form in the html, the rendering parser has not yet read the form tag, so it does not yet know what the id "eb" is when the script runs.

Place scripts after the objects they modify, if they must be in the body.

You don't need the script after the code when working with events. He only needed to include the form as a parameter (as he has done).

window.getElementById oh c'mon... It's still better handle with the document.obj how about if we try doing things this way:

var myImg = window.images["image1"];

// Switching places;

var myFrame = document.frames["frame1"];

if you really know the standard, then you should've been calling it document.forms[0].elements["TobaccoProds"].checked or you could just use document.getElementById("TobaccoProds").checked &#8212; form elements belongs to the document collections, if you want to keep those standards with you...

I know. I made a typo. I tried to edit it, but the edit button's gone. I meant document.getElementById

This article has been dead for over six months. Start a new discussion instead.