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
Solved

PHP or Javascript error when running Javascript/jQuery function

Posted on 2014-03-03
7
568 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 83

Expert Comment

by:Dave Baldwin
ID: 39901266
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 109

Expert Comment

by:Ray Paseur
ID: 39901271
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 109

Expert Comment

by:Ray Paseur
ID: 39901274
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39901288
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
ID: 39901407
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
ID: 39901420
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
ID: 39901484
Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

839 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