Results 1 to 1 of 1

Thread: Function called from onclick not working

  1. #1
    Join Date
    Jan 2008
    Posts
    8

    Function called from onclick not working

    Hi, I'm having problems getting a function to run that is called with onclick.
    Here's the function:

    function mapactions()
    {
    var p2 = document.getElementById('p2');
    var newP = document.createElement("p");
    var txt = 'Text';
    var newT = document.createTextNode(txt);
    newP.appendChild(newT);
    p2.replaceChild(newP,p2);
    }

    I'm basically trying to learn how to replace things using javascript, so this particular script doesn't have a purpose. onclick="mapactions()" is run from an option tag in a menu, but it just doesn't seem to work. I can't see anything incorrect in this. Can someone help me out?
    I really appreciate it.

    Edit: After researching a bit, I found out that this is probably caused by my Doctype being set to xhtml. I read that the DOM javascript stuff has special rules for xhtml docs, but even when I change the doctype to html, the script refuses to do anything.
    Last edited by khsater; 28 Dec 2008 at 08:46 PM. Reason: getElementById not Elements

Similar Threads

  1. animation function not workin.. please advise
    By JasonChan in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 19 Feb 2007, 11:23 PM
  2. correct use of a function?
    By numbenator in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 24 Sep 2005, 09:51 AM

Posting Permissions

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