SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Extreme basic question (grease monkey)

    Im trying to add this to my local page via grease monkey just for practicing wise

    Code JavaScript:
    document.body.innerHTML += '<center><input type="submit" onclick="alert("BooYa!")" value="Click Me !"></center>';

    somethings wrong at ** onclick="alert("BooYa!")" **

    just cant figure out how to do this..

    any advices regarding this? thanks a million
    Last edited by Mittineague; Jul 26, 2011 at 22:09. Reason: reformatting bbcode tags

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,446
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    I've seen quite a few error messages but I've never seen the "something's wrong" one

    What does the error console say?

  3. #3
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    doesnt say anything just trying to alert.. and its not

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,446
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Nitroxide View Post
    doesnt say anything just trying to alert.. and its not
    Hmmm. I tried it and it says
    Code:
    Error: syntax error
    Source File: file:///C:/My%20Documents/TEST/noalert.html
    Line: 1, Column: 5
    Source Code:
    alert(
    with a _____^ pointing to after the parenthesis

    Makes me think it might be the use of unescaped double quotes again.

  5. #5
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mmm any idea how to fix it?

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,446
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    It could be done more than one way, some more "messy" looking than others.

    Javascript uses single and double quotes to "group what's inside" them.

    The problem comes when you have them nested inside of each other. eg.

    instead of grouping like
    "outer "inner1 " inner2" end inner1" end outer"

    it thinks you mean
    "outer "inner1 " inner2" end inner1" end outer"

    So you can switch back and forth between single and double quotes

    And you can try escaping quotes for the ones meant to be written rather than interpreted in that line as code eg.
    "outer 'inner1 \" inner2\" end inner1' end outer"


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
  •