Click to See Complete Forum and Search --> : Add Element to the DOM tree


Ruchi Bhindwale
06-23-2007, 06:15 PM
The code displays hello as soon as the user clicks on the button but the text dissappears as soon as the click button is released. Why is it not static ? Is it because of the onClick event???Here's the code

<HTML>
<HEAD>
<TITLE>Select Sample Example</TITLE>
<SCRIPT type="text/javaScript">
function test()
{
var textblock=document.createElement("p");
var txt = document.createTextNode("hello");
textblock.appendChild(txt);
document.getElementById("myform").appendChild(txt);
}

</SCRIPT>
</HEAD>

<BODY>
<FORM id="myform" method="get" action="">
<INPUT type="submit" name="Pavement_Submit" value="click" style="position:absolute;left:449px;top:200px;z-index:76" onClick=test()>
</FORM>
</BODY>
</HTML>

Can anyone please suggest what may be wrong?

Thanks

rowanparker
06-23-2007, 06:39 PM
This doesn't seem to be PHP related to me?

Ruchi Bhindwale
06-23-2007, 06:49 PM
yeah sorry , its related to java script.. posted it in the correct forum :P

Sorry again .Anyways thanks

ManWithNoName
07-06-2007, 11:21 AM
Compare with these methods:

<a href="javascript:test()">alt 1</a>
<a href="#" onClick="test()">alt 2</a>


I believe when you leave the action =”” empty the page is reloaded/sent; you should have a php/asp script defined.