views:

24

answers:

2

Not really even sure what to call what I am trying to do so I will just explain. I have a section at the top of my site that I want to display announcement type messages. Theses messages will only be relevant to members of the site. As such, I would like for when they begin to type in their username and password, the div/message to appear. There is no referencing of a database as it is a hard coded message. Let me know if I need to better explain.

+2  A: 

Handle the input's onkeydown event and have the messages appear in the div you specify for messages. After you call it once, however, you may want to unbind the event so as to not raise it over and over again each time the user presses a key.

$(function() { $('#username').keydown(function() { $('#announcement').html('Welcome to the site'); $(this).unbind('keydown'); }); });
David Morton
And I just set this in it's own .js file right? I am not an expert at javascript so sorry if that is silly.
bgadoci
You would put it in a `<script>` block.
SLaks
got it. Trying it now.
bgadoci
if my div is called #announcement do I need to have it like you have it? #announcementDiv of just #announcement?
bgadoci
whatever the id of the div is. So if the div is called announcement, then call it #announcement (the hash sign indicates you're looking for an item in the dom with the ID that matches the text following the hash)
David Morton
Same goes for the id of the textbox where the user enters his/her username.
David Morton
Figure it out. Works great.
bgadoci
A: 

You need to handle the change event for the textbox and show the message in the handler.

SLaks
change is only triggered on a textbox when the user tabs out of the control.
David Morton