?
Solved

PHP or Javascript error when running Javascript/jQuery function

Posted on 2014-03-03
7
Medium Priority
?
571 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 111

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
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 
LVL 58

Accepted Solution

by:
Gary earned 2000 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

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
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 …
Suggested Courses

777 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