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

Displaying message based on the selected text box 1

Status
Not open for further replies.

Clanger67

Programmer
Mar 28, 2002
28
GB
I am new to javascripting and I have been tasked with the following problem.

On a page there are numerous text boxes and when a user enters one of the boxes I need to display a message in a label. The message that appears will be different for each text box.

I need to know the best way of identifying the current textbox and from there displaying the correct message.


Any help would be greatly apprecaited.

David
 
Hi

Code:
<html>
<head>
<script type="text/javascript">
[b]var[/b] lab=[b]new[/b] Array();
lab[[i]'one'[/i]]=[i]'First label'[/i];
lab[[i]'two'[/i]]=[i]'Second label'[/i];
lab[[i]'three'[/i]]=[i]'Third label'[/i];
[b]function[/b] sho(what)
{
  document.getElementById([i]'label'[/i]).innerHTML=lab[what.name];
}
[b]function[/b] hid()
{
  document.getElementById([i]'label'[/i]).innerHTML=[i]''[/i];
}
</script>
</head>
<body>
<form name="fo" method="post">
<input type="text" name="one" onfocus="sho(this)" onblur="hid()">
<input type="text" name="two" onfocus="sho(this)" onblur="hid()">
<input type="text" name="three" onfocus="sho(this)" onblur="hid()">
</form>
<div id="label">
</div>
</body>
</html>

Feherke.
 
In the onfocus event just pass the name of the text box that you want to display the message in as a parameter to your method.

Example:

function displayMessage(ctlTextBox, strMessage)
{
document.forms[0].getElementById(ctlTextBox).value = strMessage)
}

<select id="MySelect" name="MySelect" onfocus="displayMessage('textBoxName', 'message');">
<options>
</select>



 
Thanks for your quick replies. Feherke I have tried out your code and it looks like it could be just what I need.

dtqbterror I am still having a look at your code, but it might be of some help as well.

Thanks once again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top