• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

JavaScript: undefined function name

Hi Experts,

On a .php page I have

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="directPromo()">

Open in new window

but I get 'directPromo' is undefined.

When I change it to:
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="document.directPromo()">

Open in new window

I get Object doesn't support property or method 'directPromo'

My directPromo is at the way bottom of my page, as follows:
<div id="divPromo" style="display:block">
		<form name="frmPromo" id="frmPromo" method="post">
			<label>Promo Code:</label>
			<input type="text" name="txtPromo" size="8" " />
			<input type="hidden" name="sess" value="<?php echo $_SESSION['cart_sess']; ?>" />
			<input type="submit" value="Apply" onclick="changePromo()" name="btnApplyPromo" />
			<center><label style="font-weight: bold; color:red;"><?php echo $_SESSION['pMSG']; ?></label></center>

<script language="javascript">
function directPromo()
	<?php if ($_GET['promo'] != '') {?>
		document.frmPromo.txtPromo.value='<?php echo $_GET['promo']?>';
		str = '<?=$postURL?>' + 'changePromo.asp?goto=products';
		document.frmPromo.action = str;
	<?php } ?>

Open in new window

Any ideas?
APD Toronto
APD Toronto
1 Solution
Dave BaldwinFixer of ProblemsCommented:
Why are you trying to change it?   'directPromo' is a standalone function you created so it will not be a property of anything in the 'document'.
APD TorontoAuthor Commented:
I just need to execute 'directPromo' when the pg loads
Is this just a typo?
Should be

You can just add in before the closing script tag, assuming this would be the end of the page.

Also you should be using
<script type="text/javascript">

language= is deprecated so could be giving you problems
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now