April 29, 2012

Javascript confirmbox + form inside it

Question by Waldema

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.

Answer by codeM0nK3Y

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

Answer by Starx

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

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!