PHPLover PHPLover - 6 months ago 13
Javascript Question

How to call a confirm function before submitting a form only on click of one submit button not on the other submit button present?

I've a following form layout:

<form action="newsletter.php" name="newsletter" id="newsletter" method="post">
<input type="submit" value="Submit" class="c-btn" id="submit_value" name="submit_value">
<input type="submit" value="Send" class="c-btn" id="send_value" name="send_value">
</form>


On clicking of a button titled Send an jQuery alert should come asking for "Are you sure to send the mail?".

If user clicks on Yes then the form shoud get submit and if user clicks on No then the form should not get submit.

When user clicks on the submit button with value Submit then this alert should not come and the form should submit normally.

How can i do this ?

Answer
<form action="newsletter.php" name="newsletter" id="newsletter" method="post">
  <input type="submit" value="Submit" class="c-btn" id="submit_value" name="submit_value" onclick="return confirm('Are you sure to send the mail?');">
  <input type="submit" value="Send" class="c-btn" id="send_value" name="send_value">
</form>

Check here