Solved

PHP or Javascript error when running Javascript/jQuery function

Posted on 2014-03-03
7
569 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
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39901274
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

696 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