Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery (or just JS) choosing from multiple form submit buttons in onSubmit function
    primarykey
    data
    text
    <p>I've got a form that has multiple submit buttons. One for changing data in a database, one for adding, and one for deleting. It looks like this:</p> <pre><code>&lt;form action="addform.php" method="post" id="addform" onSubmit="return validate(this)"&gt; &lt;select name="listings" id="listings" size="1" onChange="javascript:updateForm()"&gt; &lt;!-- Here I have a php code that produces the listing menu based on a database query--&gt; &lt;/select&gt; &lt;br /&gt; Price: &lt;input type="text" name="price" id="price" value="0"/&gt;&lt;br /&gt; Remarks: &lt;textarea name="remarks" wrap="soft" id="remarks"&gt;&lt;/textarea&gt;&lt;br /&gt; &lt;input type="submit" value="Update Database Listing" name="upbtn" id="upbtn" disabled="disabled"/&gt; &lt;input type="submit" value="Delete Database Listing" name="delbtn" id="delbtn" disabled="disabled"/&gt; &lt;br /&gt; &lt;input type="submit" value="Add Listing to Database" name="dbbtn" id="dbbtn"/&gt; &lt;input type="button" value="Update Craigslist Output" name="clbtn" id="clbtn" onClick="javascript:updatePreview();"/&gt; &lt;/form&gt; </code></pre> <p>There are actually more elements in the form, but that doesn't matter. What I want to know is, for my validation method, how can I check which submit button has been clicked?</p> <p>I want it to do the following:</p> <pre><code> function validate(form){ if (the 'add new listing' or 'update listing' button was clicked'){ var valid = "Are you sure the following information is correct?" + '\\n'; valid += "\\nPrice: $"; valid += form.price.value; valid += "\\nRemarks: "; valid += form.remarks.value; return confirm(valid);} else { return confirm("are you sure you want to delete that listing"); } } </code></pre> <p>I assume there must be some way to do this relatively easily?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload