PDA

View Full Version : function calling different values



kitten2781
01-23-2007, 12:06 AM
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?

jscheuer1
01-23-2007, 05:58 AM
<!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>