How do I stop link a Text input to a Submit button?

R

Robert S

I have a rather large page with an arbitrary number of "submit"
buttons. When a user enters something in a Text field and presses the
"Enter" key, the wrong action occurs (usually the "Delete" key gets
pressed!).

I am unable to subdivide the page into multiple Forms because all of
the data in the text fields needs to be updated when any of the Submit
buttons gets clicked.

How can I link a Submit button to a specific Text input?
 
A

aaron.reese

Robert said:
I am unable to subdivide the page into multiple Forms because all of
the data in the text fields needs to be updated when any of the Submit
buttons gets clicked.


Why does that stop it from being in multiple forms. I am assuming you
are using PHP or PERL to subit the field values either to another
function or to an SQL update/insert string. If all the fields need to
be validated/updated then why not just have one submit button. If only
the field associated with the submit button needs to be
updated/inserted, then each field should be in a separate form. If you
want to do it client-side rather than server side, you could set the
on_click event of each submit button to run a javascript function to
carry out the validation. This function could take an argument which
would be the submit button clicked on.

If I've missed the point, then please repost with an example of your
problem
 
J

Jukka K. Korpela

Robert S said:
I have a rather large page with an arbitrary number of "submit"
buttons. When a user enters something in a Text field and presses the
"Enter" key, the wrong action occurs (usually the "Delete" key gets
pressed!).

This is a special case (and apparently a particularly nasty case) of the
problem "how do I prevent a form from being submitted when the user hits
Enter?". The answer is, more or less, "You don't; cope with it when it
happens".

See http://ppewww.ph.gla.ac.uk/~flavell/www/formquestion.html

The safe, though sometimes a bit clumsy, approach is that you don't have
several submit buttons (when the form contains at least one text input
field).

This means that you don't have, say, "Delete", "Add" and "Change" submit
buttons. Instead, you have e.g. radio buttons for selecting the action to be
made, with such values, and a single submit button.
 
R

Robert S

Jukka said:
The safe, though sometimes a bit clumsy, approach is that you don't have
several submit buttons (when the form contains at least one text input
field).

I think you have the hang of the problem. There are a lot of <input>
controls on the page and they all need to be submitted when any of the
"submit" buttons are pressed. The first "submit" button on the page is
the one that gets "pressed" when a user presses "Enter". I might try
creating a hidden button that refreshes the page when a user presses
Enter. That will prevent any damage from occurring. Anyone like to
tell me how to create a hidden "submit" button?
 
A

Alan J. Flavell

Is the "Delete" key your first submit button?
This is a special case (and apparently a particularly nasty case) of
the problem "how do I prevent a form from being submitted when the
user hits Enter?". The answer is, more or less, "You don't; cope
with it when it happens".

I'll go along with that...
See http://ppewww.ph.gla.ac.uk/~flavell/www/formquestion.html
thanks...

The safe, though sometimes a bit clumsy, approach is that you don't
have several submit buttons (when the form contains at least one
text input field).

Right. However, to the best of my recollection (see my web page for
details, though), *if* the form is submitted in this way, *and* the
focus is not on one of the submit controls, then one of the following
happens:

1 - No name=value attribute corresponding to a submit control is sent

2 - The name=value attribute corresponding to the *first* submit
control is sent.

The first case should be easy to deal with.

The second one can be handled by making the first submit control
be something harmless, such as "Preview".
This means that you don't have, say, "Delete", "Add" and "Change"
submit buttons. Instead, you have e.g. radio buttons for selecting
the action to be made, with such values, and a single submit button.

It's a reasonable option, indeed. But the other approach can be
slightly more convenient for the user, and I don't recall any browser
on which it causes problems.

cheers

(Excuse the pedantry with referring to "submit controls", but I'm
always worried about possible confusion with <input type=button> and
<button> when one's talking about "buttons".)
 
S

Steven Saunderson

I think you have the hang of the problem. There are a lot of <input>
controls on the page and they all need to be submitted when any of the
"submit" buttons are pressed. The first "submit" button on the page is
the one that gets "pressed" when a user presses "Enter". I might try
creating a hidden button that refreshes the page when a user presses
Enter. That will prevent any damage from occurring. Anyone like to
tell me how to create a hidden "submit" button?

I put a dummy button after the text boxes :

<input type="submit" name="none" value="" style="visibility:hidden">

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top