JavaScript - Need to refresh <div> element only

Asked By harendra singh on 15-Jul-09 07:03 AM

HI i made a html page

<html>

<div>

<script type="text/javascript" src="http:/testin.com/time.js"></script>

</div>

<div><input type=button></div>

</html>

Now This script will put one banner here when page load.

Now i want that when ever i click on button it reload/refresh without refreshing the page.

refreshing <DIV>

Venkat K replied to harendra singh on 15-Jul-09 07:47 AM

here is how we can refresh data under <div> tag:

<script type="text/javascript">
<!--
function replaceContent(show) {

     var display = new Array();
     display[1] = "Some new content.";
     display[2] = "Some other content.";
     display[3] = "Some more content.";
    
     document.getElementById("your_div").innerHTML = display[show];

}
-->
</script>
...
<a href="#" onclick="replaceContent(1)">more1...</a>
<a href="#" onclick="replaceContent(2)">more2...</a>
<a href="#" onclick="replaceContent(3)">more3...</a>
<div id="your_div"></div>

Here.

[)ia6l0 iii replied to harendra singh on 15-Jul-09 09:19 AM
Script to change the div text on button click

<script type="text/javascript">
function replaceText()
{
document.getElementById("divid").innerHTML = "replaced text."
}
</script>

the div

<div id="divid">original text</div>

the button to change the div's content
<input type="button" onclick="replaceText()" value="Click me to change the content" />

Or are you looking at something like Ajax that would render the content from a web request?

Re : Need to refresh <div> element only

Vasanthakumar D replied to harendra singh on 15-Jul-09 12:14 PM

Hi,

you can use Update panel and place the div inside update panel control.

or you can use the XMLHTTP Ajax for this.