Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
72
rated 0 times [  76] [ 4]  / answers: 1 / hits: 83890  / 11 Years ago, thu, march 14, 2013, 12:00:00

I have searched on the forum and saw posts about changing text dynamically upon click. But in my case I want to change the display dynamically when loading the page from beginning. I already have a function that figure out what I should display:



function phone()
{
//code here
return phone;
}


And my question is how to display the returned phone number in the div below to replace the 1.888.888.8888 part. Can anyone offer some insights? Thank you!



<div class=add-info>
<span class=rightfloat>Order online <span class=red>or call 1.888.888.8888</span></span>
</div>

More From » html

 Answers
33

I would change the HTML to add another <span> tag around the phone number and give that span tag an id attribute in order to access it easily (broke it up on separate lines to reduce scrolling):



<div class=add-info>
<span class=rightfloat>
Order online <span class=red>
or call <span id=contact-number></span>
</span>
</span>
</div>


Then after the page loads update the span with whatever value you want:



window.onload = function() {
document.getElementById('contact-number').innerHTML = PHONE_NUMBER_VALUE;
}


In JQuery, it would be:



$(document).ready(function () {
$('#contact-number').html(PHONE_NUMBER_VALUE);
});

[#79591] Wednesday, March 13, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elaine

Total Points: 628
Total Questions: 111
Total Answers: 104

Location: Marshall Islands
Member since Tue, Sep 21, 2021
3 Years ago
;