• I am displaying an HTML5 Dialog box on a custom post edit form. It is pretty simpla as it is just some text and 2 buttons

    <dialog id="confirmDialog">
        <p>*********</p>
        <div>
            <button value="cancel">No</button>
            <button id="confirmBtn" value="yes">Yes</button>
        </div>
    </dialog>

    For some reason when I click either button the form submits. How can I stop that?

    • This topic was modified 2 years, 3 months ago by t-p. Reason: Moved to Fixing WordPress from Developing with WordPress
Viewing 1 replies (of 1 total)
  • You haven’t indicated the type attribute for either button, so they’re both defaulting to submit.

    If your goal with the “No” button is to reset the entire form, then perhaps:

    <button type="reset" value="cancel">No</button>
    <button type="submit" id="confirmBtn" value="yes">Yes</button>

    If you don’t want to reset the form, then use type="button" for the “No” button (though I can’t really think of what you’d like to achieve with this if you don’t want this to submit the form).

    Note that value doesn’t serve the purpose you’re trying to use it for. Kindly see: https://www.w3schools.com/tags/att_input_value.asp

Viewing 1 replies (of 1 total)
  • The topic ‘Dialog Button Submitting form’ is closed to new replies.