PDA

View Full Version : Display text with no reloading



hosdank
07-29-2008, 10:10 PM
I'm a newbie to JavaScript more used to PHP and other such languages, so when I found myself in a situation that required JavaScript I was stuck. I have a onclick() event on my page wich when it's clicked i want it to display some text somewhere on the page WITHOUT THE ENTIRE PAGE RELOADING. I'd be really gratfull if anyone could offer me some help.

Thanks

Nile
07-29-2008, 10:21 PM
Here you go:


<script type="text/javascript">
function putText(el,text){
document.getElementById(el).innerHTML=text;
}
</script>
<div id="div1"></div><div id="div2"></div>
<input type="button" onClick="putText('div1','Div1 here... Nothing special...');" value="Change Div1"/>
<input type="button" onClick="putText('div2','Div2 here... Nothing special... Just kidding, you know me... :)');" value="Change Div1"/>
The first highlighted part is for the div you want to change, and the next is for the text.

hosdank
07-29-2008, 10:26 PM
Thanks SO much!!!

Nile
07-29-2008, 10:28 PM
Anytime, it was very simple. :) Just 3 codes of line in the js, and 1 code of line in the js that is important. :D