Reputation: 131
I'm having a PHP/MySQL giftlist and people can click "reserve"-button to reserve one piece of gift. Thing is that in that list there is gift which has been wished like 10 times. So to reserve all 10 pieces of certain gift one has to click the reserve-button 10 times and javascript always confirm if one is willing to reserve one piece of that gift.
What I'm now after is that change that javascript confirm to confirm+form which will send data to action.php.
In HTML it would look like this:
<p>How many piece of gift are you willing to reserve?</p>
<form action="action.php" method="post">
<input type="text" name="giftammount" />
</form>
And when confirm returns true it will submit the answer and action.php will do the magic for MySQL table.
So, is this even possible technically? Not that i've tried, i've spent several hours wondering this but can't figure this out.
Upvotes: 0
Views: 115
Reputation: 78971
Javascript confirm box and a form are two totally different things.
One way you can solve this, is creating a modal box and simulating a confirm box + confirm dialog effect.
Few other functions like alert()
, confirm()
and prompt()
only take text but not HTML
Upvotes: 0
Reputation: 4761
The following might help
If the function confirmAction returns true the form will be submitted and else the form will not. If the confirm process requires ajax , you can use jquery ajax function with asnc:true
function confirmAction(){
//return true or false
}
<form action="action.php" onsubmit="return confirmAction()" method="post">
<input type="text" name="giftammount" />
</form>
Upvotes: 0
Reputation: 798
If you're using jQuery UI then the dialog widget could be just what you need:
Use a modal dialog to require that the user enter data during a multi-step process. Embed form markup in the content area, set the modal option to true, and specify primary and secondary user actions with the buttons option.
Take a look at the jQuery UI page for an example and basic code
Upvotes: 1