Shadowing Posted June 12, 2012 Share Posted June 12, 2012 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 More sharing options...
eTianbun Posted June 12, 2012 Share Posted June 12, 2012 Is it that you just want the chat box to be the only place where 'enter' key is not accepted? Link to comment Share on other sites More sharing options...
Shadowing Posted June 13, 2012 Author Share Posted June 13, 2012 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 More sharing options...
eTianbun Posted June 13, 2012 Share Posted June 13, 2012 Well, to be sincere, your explaination is not clear enough (To me), maybe you can describe what you want in a better terms. Link to comment Share on other sites More sharing options...
Ingolme Posted June 13, 2012 Share Posted June 13, 2012 You should only be detecting the onkeydown event for that particular input and not for any other input on the page. Link to comment Share on other sites More sharing options...
Shadowing Posted June 13, 2012 Author Share Posted June 13, 2012 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 More sharing options...
Ingolme Posted June 13, 2012 Share Posted June 13, 2012 Your problem is having the keydown event on the root. Put the keydown event on the particular text input you're trying to read. Link to comment Share on other sites More sharing options...
eTianbun Posted June 13, 2012 Share Posted June 13, 2012 (edited) 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 June 13, 2012 by CodeName Link to comment Share on other sites More sharing options...
Shadowing Posted June 13, 2012 Author Share Posted June 13, 2012 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 More sharing options...
eTianbun Posted June 13, 2012 Share Posted June 13, 2012 Did you see the example above? Link to comment Share on other sites More sharing options...
Shadowing Posted June 13, 2012 Author Share Posted June 13, 2012 Oh nice thanks guys lol. that was really simple. idk why i didnt think it worked like that, idk the input closing tag was a accident lol not sure why i did that in the example. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now