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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tricky Javascript Changing-text thing. Is it possible?

Status
Not open for further replies.

handleamericanterm

Programmer
May 4, 2008
1
GB
Ok, basically I'm using this code in an attempt to get the text in the div in the tiptext function to change:


<script type="text/javascript">

var textBlocks = new Array(
'Message 0',
'Message 1',
'Message 2',
'Message 3');

function changetext(elemid) {
var ind = document.getElementById(elemid).selectedIndex;
document.getElementById("display").innerHTML=textBlocks[ind];
}
</script>

<select name="type" id="search" onchange="changetext('search');">
<option value="0">Mess 0</option>
<option value="1">Mess 1</option>
<option value="2">Mess 2</option>
<option value="3">Mess 3</option>
</select>

<img src="images/layout/icons/help.gif" alt="What do these terms mean?" onMouseover="tiptext('<div id=display>Message 0</div>');" onMouseout="closetip()">

Quick note, the tiptext('') function is a tooltip that CAN use HTML normally. However this time, when the div is inside the tiptext() function, it doesn't change the text inside the div. If the div is removed from the tiptext() function it works as it should. Is there any way I can get this to work?

P.S - 'display' doesn't have to be a div, it can also be a <span> if that helps at all.
P.P.S - I'll check back very regularly, hope you guys can help.

 
I'm not sure whether you're asking for help with the "tiptext" function, or with your own "changetext" function. If the former, then you'd need to provide the code for it...

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
And for your changetext function, you can't use getElementById because it's only text. It's not an element yet.

Try this:
Code:
function changetext(elemid) {
  var ind = document.getElementById(elemid).selectedIndex;
  document.getElementById("[b]myImageID[/b]").onmouseover=new Function("tipText('<div id=display>" + textBlocks[ind] + "</div>')");
}

Make sure you give your image an ID and have it match what is in the function.

Adam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top