Solved

JavaScript: undefined function name

Posted on 2013-02-04
3
287 Views
Last Modified: 2013-02-04
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">
			<p>
			<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" />
			</p>
			<center><label style="font-weight: bold; color:red;"><?php echo $_SESSION['pMSG']; ?></label></center>
		</form>

</div>
</body>
<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;
		document.frmPromo.submit();
	<?php } ?>
}
</script)
</html>

Open in new window


Any ideas?
0
Comment
Question by:APD_Toronto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38852921
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'.
0
 

Author Comment

by:APD_Toronto
ID: 38853295
I just need to execute 'directPromo' when the pg loads
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 38853314
Is this just a typo?
</script)
Should be
</script>

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

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

language= is deprecated so could be giving you problems
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question