jaymc Posted October 4, 2006 Share Posted October 4, 2006 [code]<INPUT TYPE = Button VALUE = "Click Me" OnClick = "document.write('Hello World')">[/code]Pretty simple right?Well, it works... but not the way I want it too!When clicking, the javascript writes 'Hello World' to the document, but deletes all the content. So, in this example, the form button disapearsI want it to just write 'Hello World' underneath the form button for exampleHow can this be achieved Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/23035-this-is-probably-really-easy/ Share on other sites More sharing options...
yonta Posted October 5, 2006 Share Posted October 5, 2006 How about putting a div below the submit button, and google about javascript's getElementById and innerHTML? Yes, this is really easy. Too easy to give you the full answer. Just google. Quote Link to comment https://forums.phpfreaks.com/topic/23035-this-is-probably-really-easy/#findComment-104071 Share on other sites More sharing options...
ldsmike88 Posted October 5, 2006 Share Posted October 5, 2006 Instead of telling it to write it over the document, try giving it a spacific div tag to write it to. Try using something like this:[code]<INPUT TYPE = Button VALUE = "Click Me" OnClick = "document.getElementById('myDivID').write('Hello World')"><div id = "myDivID">It will appear here.</div>[/code]Tell me if it works. Quote Link to comment https://forums.phpfreaks.com/topic/23035-this-is-probably-really-easy/#findComment-104086 Share on other sites More sharing options...
jaymc Posted October 6, 2006 Author Share Posted October 6, 2006 That did not work Quote Link to comment https://forums.phpfreaks.com/topic/23035-this-is-probably-really-easy/#findComment-104718 Share on other sites More sharing options...
fenway Posted October 6, 2006 Share Posted October 6, 2006 Nor can it... only the document DOM object has a .write method. However, you can set its .innerHTML instead. Quote Link to comment https://forums.phpfreaks.com/topic/23035-this-is-probably-really-easy/#findComment-104999 Share on other sites More sharing options...
yonta Posted October 7, 2006 Share Posted October 7, 2006 So basically[code]<INPUT TYPE = Button VALUE = "Click Me" OnClick = "document.getElementById('myDivID').innerHTML='Hello World'"><div id = "myDivID">It will appear here.</div>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23035-this-is-probably-really-easy/#findComment-105491 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.