SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast bbmx952's Avatar
    Join Date
    Feb 2005
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trigger a function with button!

    I have a button that I want to trigger a javascript function:
    Code:
    <input name="button" type="button" value="Start" onClick="start()">
    When I click it in Firefox it triggers the function, but in IE it says "Object doesn't support this action" Any suggestions?

  2. #2
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try onClick="javascript:start();"
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  3. #3
    SitePoint Enthusiast bbmx952's Avatar
    Join Date
    Feb 2005
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope, no good...

  4. #4
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you double checked your actual function? How about making sure that the new Windows/IE security features are not prohibiting the funtion from running?
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  5. #5
    SitePoint Enthusiast bbmx952's Avatar
    Join Date
    Feb 2005
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it to work like this:
    <a href="#" onClick="javascript:start();"><input name="button" type="button" value="Start"></a>

  6. #6
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, hold everything. This can never be correct:
    try onClick="javascript:start();"
    and more generally using javascript: is the wrong approach in almost every script. Most people have no idea what it even does(Possibility?). I would suggest you never use javascript: or eval() in any of your scripts.

    The reason your button doesn't work in IE is because start() happens to be an IE specific function, which is not supported by an <input> element. That's just bad luck with the name you chose for your function.

  7. #7
    SitePoint Enthusiast bbmx952's Avatar
    Join Date
    Feb 2005
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it to work by changing the function name, and Im kind of currious 7stud, if not javascript then what should be used???

  8. #8
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    javascript: is a pseudo-URL that allows a link to execute a script. Its only appropriate usage in HTML markup is as the href value of a link, as in:

    <a href="javascript:doStuff();">do stuff</a>

    When event handlers like onclick or onmouseover are called, they are already set to invoke JavaScript scripts.

    Note that the javascript: pseudo-URL can be typed directly into the browser's location window, to execute ad hoc scripts on the current page. As an example, cut and paste (or type) the following into your browser's location window, then hit enter:

    javascript:alert(this.location.href);

  9. #9
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its only appropriate usage in HTML markup is as the href value of a link, as in:

    <a href="javascript:doStuff();">do stuff</a>
    Which is bad js coding practice, so you shouldn't even use it there. A person with js disabled will be stuck dead in the water with that link. Instead, you should use a default page in the href for people without js, and for people that have js, you can add an onclick event which does something, and then returns false to prevent the click from loading the href page.

    Im kind of currious 7stud, if not javascript then what should be used???
    Nothing--like you had in your original post. When you see scripts with javascript: or eval() everywhere, you can be assured the person who wrote the script doesn't have a very good understanding of javascript.

  10. #10
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    'javascript:' allows bookmarklets to be used as well.

    Just a note, that would be copy and paste, not cut and paste.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  11. #11
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The generic use of the term "cut and paste" for any such text duplication operation, dates at least back to the IBM MTST, in the late 1960's. About the same time "search and replace" became better known as "search and destroy".

    Using the far more recent and generally better-known WordStar keystrokes, Cut, Ctrl+X will serve the purpose as well as Copy, Ctrl+C.


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
  •