PDA

View Full Version : Function called from onclick not working



khsater
27 Dec 2008, 01:51 PM
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.