View Full Version : unable to get DIV's content to change using javascript and DIV's id

10-11-2011, 12:10 PM
I am trying to get a div's content to change using javascript but for some reason it is not working and i get no errors looking at the error console.

the code that is waiting for the content...
<div style="font-weight: bold;">count = <div id="desc" style="float: left;"></div> descriptions to do.</div><br clear="all" />
the code that should change the content....
<? echo("<script type=\"text/javascript\">
document.getElementById('desc').value='" . $count . "';

when i view the source code the javascript lines show like so...
<script type="text/javascript">

do i have the javascript correct ?

10-11-2011, 12:16 PM
<script type="text/javascript">

value? A DIV element has no native value attribute. It is not a form's element. You may use other various methods. innerHTML is the most used, perhaps.

But? Why do you use javascript as an intermediate for that? Should not be simpler to write that straight in php?

<div id="desc" style="float: left;"><?php echo $count; ?></div>

10-11-2011, 02:30 PM
thank you i figured it out that it was innerHTML

reason i am doing this is that the content is created dynamically and while it is created it counts the entries printed and i wanted the total at the start of the page and not at the end. so once finished the javascript at the end of the page has the total placed, and this then updates the div at the start of the page.

seems to work now that i am using the correct method to update the div.

thanks for your input.