View Full Version : Changing Text in a Div Tag
w0lf42
08-15-2003, 10:54 AM
I am working on functionality for a form. When a user mouse overs the form fields, it displays text in a box in on the right-hand-side of the page. LINK (http://www.msworkshop.com/upload/dandd/login.html) (this code only works on Mozilla 1.4 and IE 6.0)
I am currently doing it with the following code:
function displayText( obj, divName , txt ) {
document.getElementById(divName).innerHTML = txt;
} // end displayText
Where the 'txt' is sent via the JavaScript function. The 'divName' is the name of the <div> tag where the text is written.
Any suggestions on a better way to accomplish this would be greatly appriciated.
Horus_Kol
08-15-2003, 11:16 AM
seems perfectly fine to me.
w0lf42
08-15-2003, 11:33 AM
The reason I bring this up is that I can see that the HTML tags may become very long.
onMouseOver="displayText(this, 'adultRegGroup', 'Enter anything you want. If you think using your email address is helpfull, then use it')"
Imagine if I had a fairly lengthy message to include. Also, I have to place escape characters for all quotation marks.
I'm just trying to come up with the easiest to manage code.
Synchronium
08-15-2003, 12:01 PM
Here's how I did what I think you're trying to do:
<script language="JavaScript">
<!-- Begin
var description = new Array();
description[0] = "Click Here To Get Access To All Areas Of The Site.";
description[1] = "Establish Contact Here.";
description[2] = "Need Help? Just Click!";
description[3] = "Hackstar Publications ©";
description[4] = "Enter Your Email Address Here.";
description[5] = "Enter Your Password Here.";
description[6] = "Submit Your Information.";
description[7] = " ";
description[8] = "Click For More Information.";
description[9] = "Click Here To Visit The Hackstar Forum.";
description[10] = "Click Here And Enter The Hackstar Chatroom";
description[11] = "Please Click Here To Help Hackstar";
description[12] = "Our Hit Counter";
// End -->
</script>
Here we have an array in which all possible text to be called is stored.
<a id="Words"> </a>
Here is the anchor (not using <div />) in which the text will be displayed.
<a href="help.htm" onmouseover="Words.innerHTML = description[2];" onmouseout="Words.innerHTML = description[7]">Help</a>
And here is an example of an element to which the effect is applied.
Work with it, modify it, etc...
w0lf42
08-15-2003, 01:37 PM
That is a good suggestion. However, I'm attempting to create a JS file that will b e dynamic enough to handle any number of form elements.
Dennis
08-15-2003, 02:19 PM
i think that the solution posted by Synchronium is the best.
You can create an external javascrip file containing an array with all the desctiption, and than modify the function..
are you able to do this thing or isn't it what you are looking fot?
w0lf42
08-15-2003, 03:34 PM
Unfortunately, I am constructing a system for a few people who have no JavaScript background and will be hesitant enough to mess around with simple arrays in JS that they may mess up the code.
I would like to have each text string reside in a <div> tag which I can display via the JavaScript (and hide all of the others) when the proper event is triggered.
Vincent Puglia
08-16-2003, 12:25 PM
Hi,
Is this what you are looking for?
the javascript:
function displayText( obj, divName) {
document.getElementById(divName).innerHTML = description[obj.id];
}
var description = new Array();
description['a'] = "Enter anything you want. If you think using your email address is helpfull, then use it";
description['b'] = "Establish Contact Here.";
description['c'] = "Need Help? Just Click!";
description['d'] = "Hackstar Publications ©";
description['e'] = "Enter Your Email Address Here.";
description['f'] = "Enter Your Password Here.";
the html:
<a href='' id='a' onMouseOver="displayText(this, 'a1')">the link</a>
<div id="a1">a1 div</div>
<div id='a2'>a2 div</div>
Vinny
Synchronium
08-17-2003, 07:59 AM
Although effective, he doesn't want to use a JS array.
To me it seems the simpler option.
You COULD just make a list of text and incorperate it into the JS array "behind the scenes" with PHP. It would involve opening the file, reading the gfile, splitting the file by lines and writing the JS array on the fly.
...But its really not hard to edit a JS array...
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.