Solved

force form submit() specify button

Posted on 2011-09-02
11
253 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

757 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

20 Experts available now in Live!

Get 1:1 Help Now