Solved

PHP or Javascript error when running Javascript/jQuery function

Posted on 2014-03-03
7
570 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
[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
  • 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 110

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
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

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