Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Submitting A Form Using Enter.
Old 08-07-2007, 05:28 PM Submitting A Form Using Enter.
Zork's Avatar
Extreme Talker

Posts: 201
Trades: 0
...With a twist!

Hey guys, and thanks for looking.

I have a combobox, such as this:
<form>
<select size=10>
<option>
<option>
<option>
<option>
<option>
</select>
<input type=submit>
</form>

I am also using JS to bring focus to this element on page load. My goal is to have keyboard-only based control. Is there anyway I can submit the form when the user presses enter, while the focus is still in the select box.

I understand they can use TAB then press enter, but I'd like to avoid that.

Thanks for all of your help,

Devin
__________________
"Computer games don't affect kids. I mean, if Pacman affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music..."
Zork is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-07-2007, 11:17 PM Re: Submitting A Form Using Enter.
Extreme Talker

Posts: 238
Location: United States
Trades: 0
Something like this would work:

Code:
function onEnter(e){
    var keynum;
    
    if(window.event){
        // IE
        keynum = e.keyCode;
    }elseif(e.which){
        // Gecko & Opera
        keynum = e.which;
    }
    
    if (keynum == 13){
        // 13 = return
        document.form_name.submit();
    }
}
HTML Code:
<select onkeypress="onEnter(event);">
__________________
The interlocking pieces of web development: usability, performance, accessibility, and standards.
frost is offline
Reply With Quote
View Public Profile
 
Old 08-08-2007, 01:46 AM Re: Submitting A Form Using Enter.
Zork's Avatar
Extreme Talker

Posts: 201
Trades: 0
Thank you very much! I really appreciate the help. My final code looks like this for anyone searching for a solution:

<script>
function onEnter(e){
var keynum;

if(window.event){
// IE
keynum = e.keyCode;
}elseif(e.which){
// Gecko & Opera
keynum = e.which;
}

if (keynum == 13){
// 13 = return
document.form_name.submit();
}
}
function onEnter(e)
</script>
__________________
"Computer games don't affect kids. I mean, if Pacman affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music..."
Zork is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Submitting A Form Using Enter.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11703 seconds with 12 queries