Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    431
    Thanks
    6
    Thanked 3 Times in 3 Posts

    unable to get DIV's content to change using javascript and DIV's id

    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...
    Code:
    <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....
    Code:
    <? echo("<script type=\"text/javascript\">
    document.getElementById('desc').value='" . $count . "';
    </script>");
    ?>
    when i view the source code the javascript lines show like so...
    Code:
    <script type="text/javascript">
    document.getElementById('desc').value='373';
    </script>
    do i have the javascript correct ?

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Code:
    <script type="text/javascript">
    document.getElementById('desc').value='373';
    </script>
    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?
    PHP Code:
    <div id="desc" style="float: left;"><?php echo $count?></div>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Oct 2009
    Posts
    431
    Thanks
    6
    Thanked 3 Times in 3 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •