Solved

force form submit() specify button

Posted on 2011-09-02
11
254 Views
Last Modified: 2012-08-13
I have a function onclick an image.
At the end of the function I want the page form to submit
document.form1.submit();

Can I specify another parameter on the submit? I want to pretend that someone clicks the real submit button.
My asp page is looking for submit = "" or not. How can I make that not blank?
0
Comment
Question by:rivkamak
  • 3
  • 2
  • 2
  • +1
11 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36475486
<form onsubmit="return false;">
And onclick of your image button :
OnClick="document.forms[0].onsubmit=null"
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36475491
<form onsubmit="return false;">
And onclick of your image button :
OnClick="document.forms[0].onsubmit=null;document.forms[0].submit()"
0
 
LVL 29

Expert Comment

by:Badotz
ID: 36476063
Instead of inlining your JavaScript, create a function to do the submittal and forget form onsubmit="return false; altogether.
0
 

Author Comment

by:rivkamak
ID: 36482083
Let me show you my code:

this is the function I run onclick of the button:
<Script>
function deleteFun(num) {
document.form1["newAmount" + num].value = 0;
document.form1.submit();
}
</script>

Open in new window


But then I need ASP code to run. This code runs if a different button on the page is clicked.
IF Request( "input" ) = "Keep Shopping" THEN
response.redirect("donors_page_open.asp")
end if 

Open in new window


How can I get the form to fake that the input button "keep shopping" was really selected?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 29

Expert Comment

by:Badotz
ID: 36482249
Pass a parameter to the ASP page, either in a hidden text field or in the URL.
0
 

Author Comment

by:rivkamak
ID: 36497563
Let me rephrase the question. Here is my code.
 It's a shopping cart. Based on what they click it will bring them back shopping or checkout. I need to somehow have a delete item next to each item. I need to be able to keep track on which item they want to delete. I thought to use a onclick feature. But then the page doesn't update properly

How else can I make a button or image per item to delete only that id?

<form id="form1" name="form1" method="get" action="cart.asp">
          <table width="599" border="0" cellpadding="0" cellspacing="0" >
            <tr bgcolor="#f0f0f0" >
              <td width="13" height="24" valign="top">&nbsp;</td>
              <td width="121" valign="top"><strong>Product</strong></td>
              <td width="49" valign="top"><strong>Price</strong></td>
              <td width="98" valign="top"><strong>Quantity</strong></td>
              <td width="159" valign="top"><strong>Cost</strong></td>
              <td width="159" valign="top">&nbsp;</td>
              </tr>
            <% 
'FOR i = 1 TO 46

For Each key In Request.Cookies("itemID")
i = CStr(key)
IF request.cookies("itemAmount")(i) <> "" THEN
IF request.cookies("itemAmount")(i) > 0 THEN

%>
            <tr bgcolor="#d9f5fa">
              <td valign="top">&nbsp;</td>
              <td valign="top" class="cartPrizes"><%=request.cookies("itemName")(i)%></td>
              <td valign="top" class="remove">$<%=request.cookies("itemCost")(i)%></td>
              <td valign="bottom" class="remove"><input name="newAmount<%=i%>" type="text" id="newAmount<%=i%>" value="<%=request.Cookies("itemAmount")(i)%>" size="4" /></td>
              <td valign="bottom" class="remove">$<%=(request.cookies("itemCost")(i)*request.Cookies("itemAmount")(i))%></td>
              <td valign="bottom" class="remove"><!-- <input type="button" name="delete" id="delete" value="Delete" onclick="deleteFun(<%'=i%>);" /> --></td>
              </tr>
            <% 
END IF
costItem=(request.cookies("itemCost")(i)*request.Cookies("itemAmount")(i))
totalCost = totalCost + costItem
END IF 

NEXT
%>
            <tr  bgcolor="#d9f5fa" >
              <td height="25" colspan="6"><table width="233" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="233"><label> </label>
                    <div align="right">
                      <input name="updateQ" type="hidden" id="updateQ" value="1" />
                      &nbsp;&nbsp;&nbsp;&nbsp;</div></td>
                </tr>
              </table>
                <span class="remove"> </span></td>
            </tr>
            <tr bgcolor="#d9f5fa">
              <td height="50"  colspan="6"> <table border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="12" height="26">&nbsp;</td>
    <td width="170"><p>Total Cost: $<%=totalCost%>
      <input name="totalCost" type="hidden" id="totalCost" value="<%=totalCost%>" />
    </p>
     </td>
  </tr>
</table>
 </td>
            </tr>
            <tr bgcolor="#d9f5fa">
              <td height="44"  colspan="6">
         
         <table width="488" height="26" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="25">&nbsp;</td>
    <td width="446"><input name="input" id="input" type="submit" value="Update Cart" />
          <input type="submit" name="input" id="input" value="Keep Shopping" />
          <input type="submit" name="input" id="input" value="Checkout" /></td>
  </tr>
</table>

         
              
              </td>
            </tr>
          </table>
         
        </form>

Open in new window

0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 37114342
How about

<input type="submit" name="delete" id="delete" value="Delete item <%'=i%>" />

or

<input type="submit" name="delete_<%'=i%>" id="delete<%'=i%>" value="Delete" />
0
 

Author Comment

by:rivkamak
ID: 37115281
then in my asp when I try to see which button was pushed, how do I get back that number?

IF Request( "delete" ) = ???

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37116035
in the first one

IF right(Request( "delete" ),6) = x

in the second one you need to find the request beginning with delete_ and take right(parm,7)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now