Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    May 2006
    Posts
    216
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Javascript with an error

    I have tried different possibilities. What is actually wrong with Javascript code that it will report and error?
    Code:
    jQuery(document).ready(function() {
    
    jQuery("a.iframe").fancybox({
        'autoSize': false,
        'type' : 'iframe',
       afterLoad: function(){
       this.width = jQuery(this.element).data("width");
       this.height = jQuery(this.element).data("height");
     });
            
    });
    Error notice:

    Error: SyntaxError: missing } after property list
    });
    Need help.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,611
    Thanks
    0
    Thanked 645 Times in 635 Posts
    You have a }); missing. You open three { but only close two
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,624
    Thanks
    6
    Thanked 1,001 Times in 974 Posts
    Yes, the afterLoad function needs a closing bracket.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    If you indent your code properly and use an editor that can highlight or underline (or other visual cues) the matching braces, brackets and parentheses, then it would be easier for you to fix these kinds of syntax errors.

  • #5
    Regular Coder
    Join Date
    May 2006
    Posts
    216
    Thanks
    4
    Thanked 0 Times in 0 Posts
    I have tried and changed missing element.
    I have the following code and an error:
    jQuery(document).ready(function() {
    jQuery("a.iframe").fancybox({
    'autoSize': false,
    'type' : 'iframe',
    afterLoad: function(){
    this.width = jQuery(this.element).data("width");
    this.height = jQuery(this.element).data("height");
    }
    });
    });
    An error message:
    Error: SyntaxError: missing } after function body

    I open three { and close three

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Then the error must be somewhere else. Which line does the console say the error is at? Again, indent your code properly for easy readability.

  • #7
    Regular Coder
    Join Date
    May 2006
    Posts
    216
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Your are right. I have checked all other code inside javascript file. There was wrong */ and mistake in code. Interesting is that validation shows wrong Line and I did not see my mistake. Is there some the best javascript validator?

  • #8
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,611
    Thanks
    0
    Thanked 645 Times in 635 Posts
    There are three popular validators

    JSLint,The JavaScript Code Quality Tool (by JavaScript expert Douglas Crockford)
    ESLint (by JavaScript expert Nicholas Zakas)
    JSHint, a JavaScript Code Quality Tool
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #9
    Regular Coder
    Join Date
    May 2006
    Posts
    216
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    There are three popular validators

    JSLint,The JavaScript Code Quality Tool (by JavaScript expert Douglas Crockford)
    ESLint (by JavaScript expert Nicholas Zakas)
    JSHint, a JavaScript Code Quality Tool
    These are good but as I understand I can not test Online Web testing. Currently it is main issue that there are too many request by Javascript. You can do only Web testing.
    Last edited by toplisek; 05-30-2014 at 06:56 PM.


  •  

    LinkBacks (?)

    1. 04-17-2014, 06:29 PM

    Posting Permissions

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