Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New Coder
    Join Date
    Aug 2005
    Location
    Earth
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript Changing-text script, is this possible?

    Ok, basically I'm using this code (which works):

    Code:
    <html><head><title>whatever</title>
    
    <script type="text/javascript">
    var textBlocks = new Array(
    'Select from the list to change this box',
    'text block two',
    'text block three');
    function changetext(elemid) {
    var ind = document.getElementById(elemid).selectedIndex;
    document.getElementById("display").innerHTML=textBlocks[ind];
    }
    </script>
    
    </head><body>
    <form>
    <select id="whatever" onchange="changetext('whatever');">
    <option value="0">Select</option>
    <option value="1">one</option>
    <option value="2">Two</option>
    </select><br>
    </form>
    <div id="display">Select from the list to change this box</div>
    </body></html>
    The script changes text in the 'display' div when a different drop down menu choice is selected. Easy.

    With this simple script in mind. If you'd look at what I'm trying to do with it...


    Code:
    <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?

    Edit: 'display' doesn't have to be a div, it can also be a <span> if that helps at all.


    -----------------

    Now Solved:

    <script type="text/javascript">
    function test(){
    var ind = document.search.type.selectedIndex;

    if (0 == ind){tiptext("Information and HTML here")}

    }
    </script>

    onMouseover="test()" onMouseout="closetip()">
    Last edited by Petsmacker; 05-04-2008 at 06:19 PM. Reason: Solved


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •