I would like to assign type=submit
and type=button
in one button like
<button type="button" type="submit></button>
I need to use the type=submit
so that I can put all the answers in my database and type=button
to bring them to another modal. That's why I'd like to use both types in one button. I hope you can help me or teach some alternatives. Thank you
<form method="POST">
<div >
<input type="text" placeholder="First Name" name="firstName">
</div>
<button type="submit" data-bs-toggle="modal" data-bs-target="#confirmModal" >Next</button>
</form>
<div id="confirmModal" >
<div >
<div >
<div >
<p>Your form has been submitted</p>
</div>
<div >
<button type="button" data-bs-dismiss="modal">Confirm</button>
</div>
</div>
</div>
</div>
CodePudding user response:
You cant add more than one type on a button, usually when you try and do a submit its better to do a 'type="submit"' on the form itself, if the button is inside the form it usually recognizes it and tells the form to submit, hope that helps.
CodePudding user response:
You can't use 2 different types. But you can just use type="button"
.
Regular buttons dont fire forms only if they got type="submit"
otherwise they just perform a click action that is not bound to anything.
So since you have a <button type="button" ...>Confirm</button>
there are different ways to achive your goal.
Propably the simplest way, add a onClick submit event
<button type="button" data-bs-dismiss="modal" onClick="submit()" <==== >Confirm</button>
You can do the same thing and more stuff if you add a js file, get the button and bind a onClick event or listen to the click event (no demo here, if you not know what im talking about, read some about it here
You can give the button a
type="submit"
and change the way how modal seeks for the button. I recommendID
orCLASS
instead ofTYPE