Jump to content

JQuery PHP Form Replica


Recommended Posts

The title might sound confusing, but in essence it isn't. I want to have a JQuery function that posts the data in a textbox and then resets the value of the textbox when the enter button is pressed.

I know that to post the data I use JQuery's $.post(); which i have now become familiar with. However my problem is finding whether or not the enter button has been pressed when the textbox is in focus. I know that I would give the textbox an id, then use a JQuery selector to select the element, then use an if statement to check if the enter button is pressed.

I know that there is a function in JQuery .keyPressed(event); but how do I use the event parameter to find out if the enter button has been pressed. A google search returned me with the following result:


var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
	alert('You pressed a "enter" key in textbox');	





$('#txt').keydown(function (e){
   if(e.keyCode == 13){
       alert('you pressed enter ^_^');


but neither of these seem to work, and yes I have changed the id of the selector.

it just doesn't seem to be able to respond to the enter button being pressed.

I would prefer to be able to be able to use a <textarea> if that makes a difference.

Any help would be seriously appreciated.

Link to comment
Share on other sites

  • 2 weeks later...

I had. The problem was that i was loading a file using jquery, which didnt have the js file linked to it. I had expected that because i had it linked in the header file, and because jquery was loading the file onto a page which included the header file, the js functions would be able to be accessed by the file getting loaded by jquery

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...