• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 29. Performing Form Validation > Displaying the Form Data for Confirmat...

Displaying the Form Data for Confirmation

The most basic form of validation involves showing the user the form data he entered and asking him to confirm that he wants to submit it. The easiest way to do this is to add the form values to a string and then use alert() to display that string. Listing 29.1 shows a simple version of such a script.

Code Listing 29.1. Confirming Form Fields, Part 1

<html>
<head>
<title>Listing 29.1. Confirming Form Fields, Part 1</title>

<script language="JavaScript" type="text/javascript">
<!--

function display_data(current_form) { 

    var confirm_message = "Here's the data you entered into the form:\n" +
                          "______________________________\n\n"

    // Add the Your_Name field 
    confirm_message += "Your Name: " + current_form.user_name.value + "\n"

    // Add the Your_Email field 
    confirm_message += "Your Email: " + current_form.user_email.value + "\n"

    confirm_message += "______________________________\n\n" +
                       "Do you want to submit this data?"

    // Ask the user to confirm the submit
    var submit_ok = confirm(confirm_message)
    if (submit_ok) { 
        current_form.submit()
    } 
} 

//-->
</script>

</head>
<body>

<h3>Please fill in the following fields:</h3>

<form action="http://www.mcfedries.com/cgi-win/formtest.exe " method="post">

<b>Your Name:</b>
<br>
<input
    type="text"
    name="user_name">

<p>

<b>Your Email Address:</b>
<br>
<input
    type="text"
    name="user_email">

<p>
<input
    type="button"
    value="Submit"
    onClick="display_data(this.form)">

</form>

</body>
</html>


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint