One form > Two submits 
Author Message
 One form > Two submits

Hi,

I'm sure this is a common problem, but I can't seem to find anything
specifically on it.

I have one form that has several textboxes that the user fills in and
it submits the data to a database.  This works great.

However, on the first textbox, I have placed a button beside it and
want the user to be able to click the button after they have entered
something into the first textbox, by clicking the button I want to
execute a stored procedure to check if the value is already in the
database and if so, return the whole recordset, populating the rest of
the textboxes.

The catch is that I also want to give the user the option of not
clicking on the button to check if the record exists, and just enter
data into all of the textboxes.

If you click on the button beside the first textbox, it submits only
the first textbox to the same page.
If you click on the save button it submits all of the textboxes
(including the first one) to a different page.

I could try to use two forms, but then I would have a form inside of a
form and I don't think that will work will it?

Much thanks!

MJ



Sat, 16 Jul 2005 06:56:33 GMT  
 One form > Two submits


Quote:
> Hi,

> I'm sure this is a common problem, but I can't seem to find anything
> specifically on it.

> I have one form that has several textboxes that the user fills in and
> it submits the data to a database.  This works great.

> However, on the first textbox, I have placed a button beside it and
> want the user to be able to click the button after they have entered
> something into the first textbox, by clicking the button I want to
> execute a stored procedure to check if the value is already in the
> database and if so, return the whole recordset, populating the rest of
> the textboxes.

> The catch is that I also want to give the user the option of not
> clicking on the button to check if the record exists, and just enter
> data into all of the textboxes.

> If you click on the button beside the first textbox, it submits only
> the first textbox to the same page.
> If you click on the save button it submits all of the textboxes
> (including the first one) to a different page.

> I could try to use two forms, but then I would have a form inside of a
> form and I don't think that will work will it?

> Much thanks!

> MJ

As you've discovered, you can only have one 'submit' button per form. One of
them will have to be something like:

<input type='button' value='Click Me' onClick='do some VBScript or
javascript something()'>

Lee.

--
___________________________________

Outlook Web Access for PDA and WAP:
www.leederbyshire.com
___________________________________



Sat, 16 Jul 2005 07:27:13 GMT  
 One form > Two submits

Quote:

> As you've discovered, you can only have one 'submit' button per form.

??? You can have as many submit buttons on a form as you like.

--
Steve

Too many have dispensed with generosity in order to practice charity.
-Albert Camus



Sat, 16 Jul 2005 22:54:01 GMT  
 One form > Two submits

Quote:

> Hi,

> I'm sure this is a common problem, but I can't seem to find anything
> specifically on it.

> I have one form that has several textboxes that the user fills in and
> it submits the data to a database.  This works great.

> However, on the first textbox, I have placed a button beside it and
> want the user to be able to click the button after they have entered
> something into the first textbox, by clicking the button I want to
> execute a stored procedure to check if the value is already in the
> database and if so, return the whole recordset, populating the rest of
> the textboxes.

> The catch is that I also want to give the user the option of not
> clicking on the button to check if the record exists, and just enter
> data into all of the textboxes.

> If you click on the button beside the first textbox, it submits only
> the first textbox to the same page.
> If you click on the save button it submits all of the textboxes
> (including the first one) to a different page.

> I could try to use two forms, but then I would have a form inside of a
> form and I don't think that will work will it?

Have the first submit button change the form's action property to submit the
page to itself:

  <input type="submit" value="Check First Field" onclick='vbscript:
    me.form.action = "<%= Request.ServerVariables("SCRIPT_NAME") %>";
  '>

Note that this will submit all the fields to the first page as well. You could
just ignore all the fields but the first on that page. If you really, really
don't want the other fields submitted to the first page, you could add code to
the onclick handler to disable the fields you want suppressed; disabled fields
are not submitted.

--
Steve

When the effective leader is finished with his work, the people say it happened
naturally. -Lao-Tzu



Sat, 16 Jul 2005 22:52:19 GMT  
 One form > Two submits

Quote:

> > As you've discovered, you can only have one 'submit' button per form.

> ??? You can have as many submit buttons on a form as you like.

I know, bad choice of words - what I meant was that without some kind of
scripting they will all do the same thing and go to the same action
destination. I just think in most circumstances it's better to give just one
a type='submit' and give the ones with scripting a type='button' for
clarity. But that's just me.


Sun, 17 Jul 2005 03:03:05 GMT  
 One form > Two submits

Quote:




>>> As you've discovered, you can only have one 'submit' button per form.

>> ??? You can have as many submit buttons on a form as you like.

> I know, bad choice of words - what I meant was that without some kind of
> scripting they will all do the same thing and go to the same action
> destination. I just think in most circumstances it's better to give just one
> a type='submit' and give the ones with scripting a type='button' for
> clarity. But that's just me.

Or give the submit controls names so the active one is submitted with the form.
That way the server-side script can determine which action to take. Works even
if client-side scripting is disabled.

--
Steve

Genius is the gold in the mine, talent is the miner who works and brings it
out. -Lady Marguerite Blessington



Sun, 17 Jul 2005 19:33:56 GMT  
 One form > Two submits

Quote:




> >>> As you've discovered, you can only have one 'submit' button per form.

> >> ??? You can have as many submit buttons on a form as you like.

> > I know, bad choice of words - what I meant was that without some kind of
> > scripting they will all do the same thing and go to the same action
> > destination. I just think in most circumstances it's better to give just
one
> > a type='submit' and give the ones with scripting a type='button' for
> > clarity. But that's just me.

> Or give the submit controls names so the active one is submitted with the
form.
> That way the server-side script can determine which action to take. Works
even
> if client-side scripting is disabled.

I've never tried that. I don't suppose you could give give a very quick
example of this, please? It sounds useful.


Mon, 18 Jul 2005 01:35:18 GMT  
 One form > Two submits

Quote:







>>>>> As you've discovered, you can only have one 'submit' button per form.

>>>> ??? You can have as many submit buttons on a form as you like.

>>> I know, bad choice of words - what I meant was that without some kind of
>>> scripting they will all do the same thing and go to the same action
>>> destination. I just think in most circumstances it's better to give just one
>>> a type='submit' and give the ones with scripting a type='button' for
>>> clarity. But that's just me.

>> Or give the submit controls names so the active one is submitted with the
>> form. That way the server-side script can determine which action to take.
>> Works even if client-side scripting is disabled.

> I've never tried that. I don't suppose you could give give a very quick
> example of this, please? It sounds useful.

<%
Select Case Request("action")
  Case "Add"
    %>
    <h1>The sum is <%= CInt(Request("n1"))+CInt(Request("n2")) %></h1>
    <%
  Case "Subtract"
    %>
    <h1>The difference is <%= CInt(Request("n1"))-CInt(Request("n2")) %></h1>
    <%
  Case Else
    %>
    <form action="<%= Request.ServerVariables("SCRIPT_NAME") %>">
    <input type="text" name="n1" readonly value="7"><br>
    <input type="text" name="n2" readonly value="4"><br>
    <input type="submit" name="action" value="Add">
    <input type="submit" name="action" value="Subtract">
    </form>
    <%
End Select
%>

--
Steve

Popularity is the crown of laurel which the world puts on bad art.
Whatever is popular is wrong. -Oscar Wilde



Mon, 18 Jul 2005 04:02:47 GMT  
 One form > Two submits

Quote:







> >>>>> As you've discovered, you can only have one 'submit' button per
form.

> >>>> ??? You can have as many submit buttons on a form as you like.

> >>> I know, bad choice of words - what I meant was that without some kind
of
> >>> scripting they will all do the same thing and go to the same action
> >>> destination. I just think in most circumstances it's better to give
just one
> >>> a type='submit' and give the ones with scripting a type='button' for
> >>> clarity. But that's just me.

> >> Or give the submit controls names so the active one is submitted with
the
> >> form. That way the server-side script can determine which action to
take.
> >> Works even if client-side scripting is disabled.

> > I've never tried that. I don't suppose you could give give a very quick
> > example of this, please? It sounds useful.

> <%
> Select Case Request("action")
>   Case "Add"
>     %>
>     <h1>The sum is <%= CInt(Request("n1"))+CInt(Request("n2")) %></h1>
>     <%
>   Case "Subtract"
>     %>
>     <h1>The difference is <%= CInt(Request("n1"))-CInt(Request("n2"))
%></h1>
>     <%
>   Case Else
>     %>
>     <form action="<%= Request.ServerVariables("SCRIPT_NAME") %>">
>     <input type="text" name="n1" readonly value="7"><br>
>     <input type="text" name="n2" readonly value="4"><br>
>     <input type="submit" name="action" value="Add">
>     <input type="submit" name="action" value="Subtract">
>     </form>
>     <%
> End Select
> %>

Thanks! I've never seen that done before but it's so useful.

Lee.



Mon, 18 Jul 2005 05:55:06 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. One form, two submit buttons

2. How to allow two form submits?

3. Ca i submit two forms at a time ??

4. Submitting contents of two forms at same time

5. Two forms, two recordsets, one table --> One problem.

6. Two Questions on Method Form.Submit() in the Document Object Model

7. two forms on one page

8. one form, two actions?

9. Two actions for one request.form

10. easy one, submit form from javascript

11. Multiple Forms with one Submit

12. Form Validation when more than one submit buttons

 

 
Powered by phpBB® Forum Software