Wednesday, 2 October 2013

Want to prevent HTML form to submit by clicking ENTER

Want to prevent HTML form to submit by clicking ENTER

I make html code with forms using php. The forms have submit-buttons
(previous page, next page, interrupt etc), and therefore unexpected
actions will happens if (f.ex.) a text field is clicked and after that
ENTER is used (the first submit button then is activated) and i want to
prevent that (IE is the problem).
I want to handle this at server, not by JavaScript. How can i detect that
ENTER is clicked and not some of the submit-buttons? The POST-array looks
the same any way.
It is possible to have an field with a picture before the other
submit-buttons , and when ENTER is clicked this field is selected and
shows up in the POST-array. Like this:
echo "<input type='image' id='picture' name='picture' src='picture.jpg'>
echo "<input type='submit' name='knapp' value='<-Previous'>";
echo "<input type='submit' name='knapp' value='Interrupt'>";
echo "<input type='submit' name='knapp' value='Save and terminate'>";
But this is a very dirty solution, any better solutions?

No comments:

Post a Comment