Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determine which button is used if user hits [enter]

Status
Not open for further replies.

TKaeser

Technical User
Mar 4, 2002
16
CH
Hello,

I've asked this question before, but maybe didn't make it quite clear. (thread216-245486)

I have a form that contains 4 different submit buttons with the same name and different captions.
If the user hits his enter-key the form is always submitted by button 1. How can I change this? (to an arbitary button...)

Thanks!

Thomas

 
What you want to do can be done, but I don't believe there is a browser non-specific way to do it.

Your question might find a more experienced audience if you posted it into the "HTML and CSS" forum.
 
probably the best way is using javascript.

so the javascript phorum is the best one

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
u could always make an invisible first submit button with the value u prefer --BB
 
I would create a javascript function that detects if the user hits the enter key and stops the submit, then shows an error message like "Please use one of the submit buttons below"

<script language = &quot;javascript&quot;>
function handlePress(e) {
var whichCode = (window.Event) ? e.which : e.keyCode;

if (whichCode == 13) {

return false;
}
}

Then in the body...in the text field, add the method

onKeyPress=&quot;return handlePress(event)&quot;>

do a search on capturing keypress events in javascript for more hints...

hth



Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Thank you all for your contributions!

I've learned quite a bit from them.

In the end I've rewritten big parts of my php code, so that i can now use multiple forms (means: every button has its own form now) and mixed in some javascript.

no solution to the problem but a work-around which finally works!


Cheers
Thomas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top