Click to See Complete Forum and Search --> : [RESOLVED] div tag problem


paraglidersd
04-14-2009, 12:58 PM
Hi All. I have broken this problem down to its most basic element, though my real task is a bit more difficult. My situation is that I have a html page with javascript, and a javascript function that I want to populate an html div tag with (see the example below). What is happening is that the div tag is getting populated and displayed ever so quickly, then erased and replaced with the original html ouput. So, in my example below, I get the first div tag (div1) to display as the page loads (a form with a simple button). When the button is pushed, I populate the 2nd div tag (div2) with a simple text statement. It displays quickly then gets erased and the original display (from div1) is redisplayed by itself. I have zero clue why this is happening and I have tried many variations. Any ideas would be very helpful. I am not stuck on using the 'div' tags as my final solution if there is a better way.

<html>
<head>
<title>Summary Reports</title>
<script type.......>

function init_div_2()
{
document.getElementById('div2').innerHTML=
'<p>this is div 2</p>';
}


</script>
</head>

<body>

<div id='div1'>
<form onsubmit='init_div_2()'><input type=submit value='run' name='run'/></form>
</div>

<div id='div2'></div>

</body>
</html>

bigalc
04-14-2009, 01:12 PM
Hi, using Submit on your page will reload it (submit is normally used to send variables to a server script), so what's happening is the javascript is working, and then the page is being reloaded so you're getting the original result.

I think basically you won't be able to use your submit button to populate the second div unless you write the page in PHP or ASP or whatever and send the content to the server, which would then populate the div that way.

You could create a button, not a submit button, just <input type=button ... and then on that button put onclick='init_div_2()'. But this won't submit your form.

Is this making any sense?

Fang
04-14-2009, 02:03 PM
onsubmit='init_div_2(); return false;'

paraglidersd
04-14-2009, 02:20 PM
Thanks all for your help. Problem is solved. I appreciate it.

-Bill