Solved

PHP or Javascript error when running Javascript/jQuery function

Posted on 2014-03-03
7
564 Views
Last Modified: 2014-03-03
I'm really confused by an error I'm getting on this page:
http://www.berksfoods.com/special-offers.htm

The initial page loads fine. If you click one of the large slide-in graphics ("get coupon"), a pop-up appears as expected and as far as I can tell everything works, however in my inspector I get an error:

SyntaxError: Unexpected token ')'
special-offers.htm:1

I'm not even positive if this is a Javascript or PHP error. Line "1" of special-offers.htm is not Javascript. On this website, HTM files are configured to run as PHP scripts though.

This is the first 26 lines of code in my special-offers.htm file:

<?php	session_start();

		if (!isset($_SESSION['id'])){
			$login=0;
		} else {
			if ($_SESSION['id']==''){
				$login=0;
			} else {
				$login=1;
			}
		}

		if ($login==0){
			$promo1="<a class=\"promo\" href=\"javascript:void()\">";
			$promo2="<a class=\"promo\" href=\"javascript:void()\">";
			$promo3="<a class=\"promo\" href=\"javascript:void()\">";

		} else {
			$promo1="<a href=\"http://www.berksfoods.com/img/cpn/promo001.pdf\" target=\"_blank\">";
			$promo2="<a href=\"http://www.berksfoods.com/img/cpn/promo002.pdf\" target=\"_blank\">";
			$promo3="<a href=\"http://www.berksfoods.com/img/cpn/promo003.pdf\" target=\"_blank\">";
		}

		$pagetitle="Special Offers";
		$pagedescription="";
		include_once "_head.php"; ?>

Open in new window


I get a similar error in Safari and Firefox inspector tools. Any advice?

Thank you!
0
Comment
Question by:bbdesign
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
In the Firefox console, I see this:
Error: http://www.berksfoods.com/js/jquery-1.10.2.min.js is being assigned a //# sourceMappingURL, but already has one
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
It's probably not a PHP error.  I can't debug your code from what I can see here, but I can show you a simple jQuery/AJAX example that works correctly.  Please see the example and explanations in this article.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
In your links you have href="javascript:void()"
Since you are using jquery change it to an hash and use e.preventDefault in your functions e.g.

$("#something").onclick(function(e){
e.preventDefault()
...
0
 

Author Comment

by:bbdesign
Comment Utility
I found the problem. javascript:void() is incorrect, it needed to be javascript:void(0). I have been using that technique for a while when I want an <a> element but I don't want it to link anywhere. Is the hash tag with e.preventDefault() a better way to do that?
0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Yes, think everyone will tell you inline=bad (and that is inline js)
Of course if you are not using the href then remove it.  It would affect any styling you may have for what is supposed to be link, as removing href will make it behave like any other tag i.e. no visited attribute etc
Or since there is no point to a link in your circumstance just attach the onclick to the element itself (the image) or use another tag like div to attach to.
0
 

Author Comment

by:bbdesign
Comment Utility
Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now