/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Call function when pressing "Enter" key

I am working on an ajax panel that calls upon hitting submit. The submit button calls a function (checkRecord()) and then populates a data grid.

My question is:

I want to add functionality so when the user hits the “Enter” key then the same function gets called upon without reloading the page.

My problem:

The page gets reloaded when hitting the “Enter” key and it seems its calling my action but when the page gets reloaded it loses the call to the ajax function.

Here is my code:

[CODE]
function checkEnter(e){
var characterCode
if(e && e.which){
e = e
characterCode = e.which
}
else {
e = event
characterCode = e.keyCode
}

if(characterCode == 13){
checkRecord();
return false
}
else{
return true
}
}
[/CODE]

I am calling it like this from my form:

[CODE]
<input name=”maintxtbox” type=”text” id=”maintxtbox” onKeyPress=”checkEnter(event)” />
[/CODE]

Anyone has any suggestions so that my javascript function gets called without having to refresh the page? Thanks.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@vicpal25authorFeb 27.2007 — duh solved!

I forgot one minor thing:

[CODE]
<input name="maintxtbox" type="text" id="maintxtbox" onKeyPress="return checkEnter(event)" />
[/CODE]


return on the function call! ughgh! Thanks anyways.
×

Success!

Help @vicpal25 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...