JavaScript can do more than just check the data in forms; it can submit that data itself using a form's submit method. This is good if you want the data-submission process under your controlyou don't even have to display a submit button in the form, you can handle it all in JavaScript. Here's an example. In this case, the submit button in this web page is just a standard HTML buttonthe form's data is submitted by the JavaScript code after checking with the user : (Listing 12-06.html on the web site)<HTML> <HEAD> <TITLE>CGI Example</TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function checkData() { if(window.confirm("Upload your name?")){ document.form1.submit() } } // --> </SCRIPT> </HEAD> <BODY> <FORM NAME="form1" METHOD="POST" ACTION="http://www.starpowder.com/steve/12-03. cgi"> Please enter your name: <INPUT TYPE="text" NAME="text" VALUE=""> <BR> <INPUT TYPE="BUTTON" VALUE="Submit" ONCLICK="checkData()"> <INPUT TYPE="RESET"> </FORM> </BODY> </HTML> Tip Here's something to knowif you call the submit method, don't execute any code after that method call, because if you do, the form's data is not submitted to the server. You can see how this works in Figure 12.4, where the code is checking with the user before submitting the form's data. Figure 12.4. Using JavaScript to check with the user.
|