Tuesday, June 4, 2024
 Popular · Latest · Hot · Upcoming
140
rated 0 times [  143] [ 3]  / answers: 1 / hits: 20205  / 15 Years ago, thu, july 16, 2009, 12:00:00
<div id=diva>this is div a</div>
<div id=divb> this is div b</div>


now how can I change the text of div dynamically by button click. here also mention that all text come from a database. when I click the button then it detects the div id and replace the text with desire text.



All code will be in PHP.


More From » php

 Answers
4

This will work once the page is being loaded:



document.getElementById('diva').innerHTML = 
<?php echo functionThatReturnsSomeValue(); ?>;


Dynamically, you would need to do an AJAX call on the PHP file which outputs a value. You'd be better off if you used a JS framework such as jQuery, rather than implementing the AJAX call yourself.


[#99116] Sunday, July 12, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jakobarmandr

Total Points: 363
Total Questions: 103
Total Answers: 87

Location: Romania
Member since Mon, Jun 6, 2022
2 Years ago
jakobarmandr questions
Thu, May 13, 21, 00:00, 3 Years ago
Thu, Aug 20, 20, 00:00, 4 Years ago
Thu, Jan 2, 20, 00:00, 5 Years ago
Mon, May 13, 19, 00:00, 5 Years ago
;