Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh vars in <div> without refreshing entire page 1

Status
Not open for further replies.

xserror

Programmer
Mar 17, 2005
5
NO
As you can see from the code, I have a div tag wich displays a set of vars. I'm looking to change the content of the vars, and update the div in one operation. Thus the "changetext" button. But I've looked everywhere, and can't seem to get info on how to refresh the div without refreshing the entire page, thus loosing the updated vars.

Any help would be much appreciated. I'm also open to different ways of doing this.

---------------------------------------------------
var text1="Much to learn have you, young padawan. ";
var text2="If a Jedi wish you to become";
var text3="In a galaxy far far away. ";
var text4="A group of rebels struggle against the migthy empire";

<div>
<h1><scriptlanguage="javascript">document.writelntext1);</script></h1>
<p><script language="javascript">document.writeln (text2);</script></p>
</div>
<inputype="button" value="Changetext" onclick="text1=tekst3; text2=text4;" >
--------------------------------------------------



Nobody enjoys shooting penguins, but if you have to shoot penguins, you might as well enjoy it.
 
use the innerHTML property.

And for future reference, please post your actual code rather than typing it in. There are numerous typo's here.

example:

Code:
<script language="javascript"><!--

function ChangeText() {
    var newH1 = "blah blah";
    var newP = "more blah blah stuff";

    document.getElementById('mainH1').innerHTML = newH1;
    document.getElementById('mainP').innerHTML = newP;
}

</script>

Code:
<input type="button" onclick="ChangeText();" value="Change Text" />

<h1 id="mainH1">Default</h1>
<p id="mainP">Default</p>

*cLFlaVA
----------------------------
[tt]a frickin' twelve-gauge, what do you think?[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 

One way would be to give your div an id:

Code:
<div id="myDiv">

and then use innerHTML:

Code:
document.getElementById('myDiv').innerHTML = '<p>Some new HTML</p>';

It's not part of any standard, but works in most browsers.

Hope this helps,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
Thanks cLFlaVA.

That did the trick. Obviously I need to read up on DHTML.

As for the typos, I did cut'n'paste the actual code, but I also tried to omit certain parts that was in my language, wich would only clutter the code, and make no sense whatsoever. Guess I kinda rushed thru it..






Nobody enjoys shooting penguins, but if you have to shoot penguins, you might as well enjoy it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top