Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange behaviour on text elements.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have this simple JavaScript code, with a text to textarea function:

<script language=&quot;JavaScript&quot;>
<!--

function change_text(number)
{
if(number == 0)
document.form.textarea.value = &quot;Text element 1&quot;;

else if(number == 1)
document. form.textarea.value = &quot;Text element 2&quot;;

.
}
-->
</script>

The performance of the script is though closely related to the amount of characters in the text, where I tested have observed the following:

Test 1)

10 text elements with exactly 15 characters each is okay (loading time < 1. sec.)
10 text elements with exactly 16 characters each is NOT okay (loading time > 10 sec.)

Test 2)

4 text elements with exactly 138 characters each is okay (loading time < 1. sec.)
4 text elements with exactly 139 characters each is NOT okay (loading time > 10. sec.)

I cant se any relations between the two tests, except a significant time delay when I increase the amount of charters with one!!

I have tried the code with use of an array, but the performance is the same!

Does anyone know how to overcome this problem - so the loading of the page becomes quicker?

Thanks in advanced,

Bo
 
write first your text and then hide/show it instead of trying to write it dynamically
 
Hey iza,

I'm not sure what you mean, where do you want me to write it?

The text is received from MySQL and is supposed to be places in a textarea field (the same field) on a mouseover event (as a description of the picture where the mouseover is placed)!

The DB-connection is very fast and a simple print of the text also, but when the text is places in the JavaScript as the submitted code, the loading becomes very slow (10-15 sec!)

Regards,

Bo
 
what i say is : do not query the db to place the text onmouseover event. Instead, query the db when you build your page, populate already the textarea, and hide everything that is not supposed to be seen yet - then onmouseover, just SHOW your text - this will be really faster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top