Results 1 to 2 of 2

Thread: function calling different values

  1. #1
    Join Date
    Jan 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question function calling different values

    I have a function that prints defined text onto the page. I want the function to print the "name" of the item it is running. For example:
    <head>
    function writeNote(){
    document.FormName.TextBoxName.value = "NO SIGNAL";
    }
    </head>
    <body>
    <span id="WriteNotes" onClick="writeNote(DisplayCompleteNotes)">Text</span>
    </body>


    What this does is display "NO SIGNAL" in a defined area when "Text" is clicked with the mouse. I want to be able to have a list of values called and the function choosing the correct value that is matched with the id/name, OR have the tag id or name printed instead.

    How can I do this?
    Last edited by kitten2781; 01-23-2007 at 12:08 AM. Reason: ease of reading

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    .gt {
    cursor:pointer;
    font-family:arial, sans-serif;
    }
    </style>
    <script type="text/javascript">
    function showNote(num, id){
    var notes=[];
    notes[0]='I have a dog.';
    notes[1]='I have a cat.';
    notes[2]='You can keep them with your frog.';
    notes[3]='You can keep them in your hat.';
    var t=document.getElementById(id);
    if(t.tagName.toLowerCase()=='input'||t.tagName.toLowerCase()=='textarea')
    t.value=notes[num];
    else
    t.innerHTML=notes[num];
    }
    </script>
    </head>
    <body>
    <span class="gt" onclick="showNote(0, 'ti1');">Dog</span><br>
    <span class="gt" onclick="showNote(1, 'ti1');">Cat</span><br>
    <span class="gt" onclick="showNote(2, 'ti1');">Frog</span><br>
    <span class="gt" onclick="showNote(3, 'ti1');">Hat</span><br>
    <input id="ti1" type="text" size="33" value="I have a dog."><br>
    <span class="gt" onclick="showNote(0, 'ta1');">Dog</span><br>
    <span class="gt" onclick="showNote(1, 'ta1');">Cat</span><br>
    <span class="gt" onclick="showNote(2, 'ta1');">Frog</span><br>
    <span class="gt" onclick="showNote(3, 'ta1');">Hat</span><br>
    <textarea id="ta1" cols="33" rows="1">I have a cat.</textarea><br>
    <input type="button" onclick="showNote(0, 'sp1');" value="Dog">
    <input type="button" onclick="showNote(1, 'sp1');" value="Cat">
    <input type="button" onclick="showNote(2, 'sp1');" value="Frog">
    <input type="button" onclick="showNote(3, 'sp1');" value="Hat"><br>
    <span id="sp1" class="gt">You can keep them with your frog.</span><br>&nbsp;<br>
    <span class="gt" onclick="showNote(0, 'd1');">Dog</span> ||
    <span class="gt" onclick="showNote(1, 'd1');">Cat</span> ||
    <span class="gt" onclick="showNote(2, 'd1');">Frog</span> ||
    <span class="gt" onclick="showNote(3, 'd1');">Hat</span>
    <div id="d1" class="gt">You can keep them in your hat.</div>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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