SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help: assigning semi-colon as value..

    how do i go about doing this? i have a value that i want to assign for a variable that contains the semicolon ';' as part of the value but whenever i put one, i get an "unexpected ';' error".

    heres the code:
    var link = "onClick='java script:control("B" ); return false;'";
    Last edited by micron; Feb 26, 2003 at 03:29.

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could try escaping it like this: myvar="\;"

  3. #3
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by micron
    heres the code:
    var link = "onClick='java script:control("B" ); return false;'";
    The problem is not the semicolon, but the quotes. Corrected code:
    Code:
    var link="onclick='control(\"B\");return false;'";
    Since your string is delimited with "double quotes", you must escape double quotes within the string with backslashes (\").

    I've also removed the 'java script:' portion of your code, as it is incorred. 'javascript:' (not 'java script:') should be placed at the start of the href attribute when you want to point a link at a piece of JavaScript code. Since you're setting an event handler (onclick), not an href attribute, this is not needed.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks guys. that was it. =)


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
  •