SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript Beginner!

    Hi!

    The Follow stateman has something that i canīt figure what it does:

    var fullLink = "href=\""+this.link+"\" target=\""+this.target+"\" onClick=\"clickOnLink('"+this.getID()+"\', '"+this.link+"','"+this.target+"');return false;\"";

    What is a Regular Expression?

    What is the "\" in "href=\"...?

    I just donīt know!

    can you help me?

    Regards!!!

  2. #2
    SitePoint Addict bronze trophy AllanP's Avatar
    Join Date
    Sep 2010
    Location
    Australia
    Posts
    298
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Your variable fullLink is being generated dynamically. it should have an <a element at the beginning, before the href=.

    The \" is a way of preventing the write to page process from incorrectly thinking that the " is the end of the string started at "href=.

    The +this.link+ is a way of filling in the correct href link detail from the information stored in the page object model before the page write. It should look something like "http://www.mySite.com".

    The onclick suggests that this dynamic link may have been designed to carry out two functions; one by way of the onclick and the second via the <a href. It might also be used to make sure that people with and without javascript enabled can still use this link.

    The return false; suggests that the normal behaviour of the first href is being prevented. It all looks a bit of a mess, but its hard to tell untill the missing info is made available.

    A Regular Expression is a method of finding if specific patterns occur in a string. For instance, checking the input format of an email address to make sure it conforms to the standard.

  3. #3
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lets look again:

    var fullLink = "href=\""+this.link+"\" target=\""+this.target+"\" onClick=\"clickOnLink('"+this.getID()+"\', '"+this.link+"','"+this.target+"');return false;\"";

    in the "href=\"" the \" it tells me that the " is not the end of the string so why in the portion onClick=\" donīt have two " like onClick=\""? and more in the portion ('"+this.getID()+"\'... why have the \' again if the others statemants like next ...\', '"+this.link+"','"+this.target"')... doesn't have the \'????

    I am just beginning and i am very confuse!!

    Shouldnīt it be something like "href=\""+this.link+"\" target=\""+this.target+"\" onClick=\"clickOnLink('"+this.getID()+"',...

    i mean why have the \'... in this portion if the rest donīt ???

    Regards!!!

  4. #4
    SitePoint Addict bronze trophy AllanP's Avatar
    Join Date
    Sep 2010
    Location
    Australia
    Posts
    298
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    When you are writing a string of code to a page the positions of the " and ' are important as end markers. For instance you can use the following document.write statement within a javascript script:
    document.write("hi there");. The " in this case is indicating the ends of the string.

    If you want to use the character " somewhere within this string you need to escape it, so that the script knows that it is not the end of the string, but a part of it. Here is an example using the \' and \" characters:
    document.write("The town\'s horse \"harry\" ran away");

    The characters \' and \" in this case are interpreted as being punctuation marks, not end of string markers. The same thing applies to the string of code that was originally posted.


Bookmarks

Posting Permissions

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