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
2010-02-25 19:43:02
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
2010-02-25 19:45:27
You would put it in a `<script>` block.
SLaks
2010-02-25 19:48:24
got it. Trying it now.
bgadoci
2010-02-25 19:48:51
if my div is called #announcement do I need to have it like you have it? #announcementDiv of just #announcement?
bgadoci
2010-02-25 19:51:17
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
2010-02-25 19:52:03
Same goes for the id of the textbox where the user enters his/her username.
David Morton
2010-02-25 19:52:36
Figure it out. Works great.
bgadoci
2010-02-25 19:52:56
A:
You need to handle the change
event for the textbox and show the message in the handler.
SLaks
2010-02-25 19:43:29
change is only triggered on a textbox when the user tabs out of the control.
David Morton
2010-02-25 19:45:00