Jump to content

Using keydown


Shadowing

Recommended Posts

Hey guys im currently using keydown on the key "Enter" for people to type in a chat box i made. The problem im having is it effects all my textarea boxes too. like email etc.... Its preventing hitting enter and going to the next line cause my entire site is 100 percent ajax. So i need help figuring out how to disable and enable this. anyone have any ideasi was thinking of making it so that it enables when someone clicks on the input to type in the chat box then i'll disable it when they open up any windows/div's.

 $(document.documentElement).keydown(function(e){	      if (e.keyCode == 13) {		   	post_message();				return false;	      }    });

Link to comment
Share on other sites

Thanks for the reply CodeName. nah i want it to work in the chat box also. the problem is when i get it working in the chat box. it messes up when people hit enter to go to the next line inside a textarea. so i need to figure out how to shut it off then turn it back on again

Link to comment
Share on other sites

no problem :) lets say you I have a textarea "<textarea></textarea>"when people type into the text area and hit "enter" it goes to the next line. The browser does this by default. I have a chat box that uses <input type=text'></input>so im using this below to make it when users hit "enter" it runs the post_message function which submimts their chat message

 $(document.documentElement).keydown(function(e){              if (e.keyCode== 13) {                           post_message();                         return false;          }     });

the problem is with the code above active when a user types in the <textarea></textarea> hitting enter no longer takes them to the next line because the key enter is set only to run the post_message function so i need to beable to disable it and reenable it

Link to comment
Share on other sites

Ok, got what you mean now. just give the <input/> an id and target it.ex:

<input type="text" id="chatbox">$('#chatbox').keydown(/*function goes here!*/)

EDIT: In the last example you gave, you used </input>. NB: There is NO closing tag for <input> element.

Edited by CodeName
Link to comment
Share on other sites

You should only be detecting the onkeydown event for that particular input and not for any other input on the page.
thanks for the reply yah im wanting it so that when the users clicks on the <input> it activates it. unless there is another way of doing a statement for that?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...