views:

104

answers:

2

this is a general form code

<form name="search_form" action="" method="POST">
<input type="text" name="search_text">          
<input type="submit" name="search_bt" value="Go">
</form>

is there a way could have a confirmation dialog saying 'Yes'\'No' or 'Confirm'\'Cancel' etc...

One way i figured of dong is is with CSS Layer and JavaScript and Php... that have a php isset(){} chechk on the button and when set display a Div displayed with two buttons and onclick=func() JS function of those buttons have a php variable(flag) set and then i can if(flag){} to continue or skip some code...

well that is going to work and plus point is that i can have a well themed dialog box but i just wanna make my life easier...

+1  A: 

Using raw javascript without any div...

You can have this function

function confirmSubmit() {
  if (confirm("Are you sure you want to submit the form?")) {
    document.getElementById("FORM_ID").submit();
  }
  return false;
}

And you can call that function from the onsubmit event in the form, or on the onclick event in the button.

By the way, have you heard about JQuery. Its a JS Library with a lot of helpful things that give you a comfort and beauty way of coding javascript.

As an example of what you want to get done, take this confirmation dialog from JQuery as example

Garis Suero
i know jquery but not too muh.. and i would love to replace any JS thing with jquery... direct me to an example or sample
Junaid Saeed
well jqyery is JS but still ;p
Junaid Saeed
take this example: http://jqueryui.com/demos/dialog/#modal-confirmation and remember, that you have StackOverflow to help you in that transition... here are lot of GURU in JQuery...
Garis Suero
thank you GURU JI... all these jQ ui items... how can i change their theme to go with my site design so that it doesn't look like a Dinner Jacket with a Baggy ;p
Junaid Saeed
Guru where?... Jquery is CSS based... so you always can edit those CSS... anyhow, for your luck JQuery's people have made a ThemeRoller application, where you can select a them and/or pick a theme... just go to this link: http://jqueryui.com/themeroller/
Garis Suero
+1  A: 

You can also do it with one line in the form tag itself

<form action="<form handler>" method="post" onsubmit="return confirm('Are you sure you want to submit?')">
acqu13sce
B E A utiscriptual
Junaid Saeed
What utiscriptual means?
Garis Suero
beautifull ( script x spiritual ) = BEAutiscriptual.... beautfull holy script ;p
Junaid Saeed