views:

29

answers:

2
  1. I have an HTML form that uses a PHP file in the form tag action="" for sending the content of the form as an email.

  2. I have a simple JavaScript for required fields that is called for in the form tag onsubmit="".

  3. My PHP file returns a summary of the form after it is submitted.

All I need to add is a simple confirmation dialog box. But I'm having trouble figuring out how to do that. (Sorry, I should be a little more brilliant!) I could probably add JavaScript to my required fields code, but not sure how to do that. Here is my existing code:

function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_required(drop_point,"Please choose a Drop Point")==false)
{drop_point.focus();return false;}
if (validate_required(your_name,"Please enter your Name")==false)
{your_name.focus();return false;}
if (validate_required(email,"Please enter your Email Address")==false)
{your_name.focus();return false;}
}

}

Any help would be appreciated! Thanks!

A: 

You can just use

confirm("Are you sure you want to submit?");

It returns True or False based on Users choice

Some samples here. Is this what you are looking for?

Edit:

function validate_required(field,alerttxt)
{
   with (field)
        {
         if (value==null||value=="")
            {
              alert(alerttxt);return false;
            }

        }
return confirm("Are you want to submit the form");
}
Shoban
Eric Wenger
You can dd this to the Validateform function.. If all the required fieds are entered then you return true already in your function.. Just beofre that you can show the confirmation box and then return true or false....Clear?
Shoban
Thank you very much for your help. Can you show me where I would add the confirm() code?
Eric Wenger
Edited you code lil it.. Check and let me know... Not tested ;-)
Shoban
A: 

Shoban got me going and here is what my solution is:

function validate_form(thisform)
{
with (thisform)
{
if (validate_required(drop_point,"Please choose a Drop Point")==false)
{drop_point.focus();return false;}
if (validate_required(first_name,"Please enter your First Name")==false)
{first_name.focus();return false;}
if (validate_required(last_name,"Please enter your Last Name")==false)
{last_name.focus();return false;}
if (validate_required(drop_point_date,"Please enter the Drop Point Date")==false)
{drop_point_date.focus();return false;}
if (validate_required(email,"Please enter your Email Address")==false)
{email.focus();return false;}
if (validate_required(order_confirm,"Please confirm your order")==false)
{order_confirm.focus();return false;}
}
return confirm("Do you want to submit the form");
}

And that works perfect!

Thanks a lot! Live and learn!

Eric Wenger