dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Stumped by "Unexpected token <" error

  1. #1
    Join Date
    Sep 2017
    Posts
    2

    Stumped by "Unexpected token <" error

    Hi - JS newbie stumped by an error I can't figure out.

    Code:
    $(function(){
    
    				//setTimeout(function(){
    						
    						$("#mobile-menu").buildMbExtruder({
    							position:"top",
    							width:"100%",
    							extruderOpacity:1,
    							onExtOpen:function(){},
    							onExtContentLoad:function(){},
    							onExtClose:function(){}
    						});
    
    				//},1000);
    			});
    			function changeLayout(layout){
    				var curURL = location.href.replace(/([\&\?]layout=[a-z]*)/ig, '').split('#')[0];
    				if(curURL.indexOf('?')==-1){
    					curURL += '?';
    				}else{
    					curURL += '&';
    				}
    				curURL += 'layout=' + layout;
    				window.open(curURL, '_self');
    			}
    			$(document).ready(function(){
    				<?php if($isMobile): ?>
    					var htmlStr = '<div id="switch_layout">';
    					<?php if(getLayout()=='desktop'): ?>
    						htmlStr += '<input type="button" onclick="changeLayout(\'mobile\')" value="Return to mobile layout"/>';
    					<?php else: ?>
    						htmlStr += '<input type="button" onclick="changeLayout(\'desktop\')" value="Go to desktop layout">';
    					<?php endif; ?>
    					htmlStr += '</div>';
    					$('#site .footnote').append(htmlStr);
    				<?php endif; ?>
    			});
    When running the code through a syntax validator I get an error at line 27 (which reads: "<?php if($isMobile): ?>"): "Unexpected token <"

    Any help would be greatly appreciated!

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    4,990
    This is not a JQuery or a JavaScript error, its a PHP syntax error.

    This line <?php if($isMobile): ?> should be <?php if($isMobile){ ?> and the closing condition <?php } ?>
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    4,990
    I also note that you have other if() conditionals that have the same error.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  4. #4
    Join Date
    Sep 2017
    Posts
    2
    Quote Originally Posted by \\.\ View Post
    I also note that you have other if() conditionals that have the same error.
    Thank you!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles