Two ways to submit form forms, submit and button usage

Source: Internet
Author: User
1. When you enter the user name and password is empty, you need to judge. This is the use of verifying the user name and password, this needs to be written on the front page of the JSP, there are two ways, one is to submit with submit. One is to submit with a button.
Method One:

Insert a JS method in the header of the front page of the JSP:

function CheckUser () {
var result = document.getElementById ("userid"). Value;
var password = document.getElementById ("Userpassid"). Value;
if (result = = "") {
Alert ("User name cannot be empty");
return false;
}
if (password = = "") {
Alert ("Password cannot be null");
return false;
}else{
return true;
}
}

Write this in the form form:

<form id= "Formid" Name= "myform" method = ' post ' action = ' user_login_submit.action ' onsubmit = ' return CheckUser (); " >
<table width= "100%" border= "0" >
<tr>
&LT;TD width= "height=" align= "right" > User name &nbsp;</td>
<td><input type= "text" value= "" class= "text2" name = "username" id = "userid"/></td>
</tr>
<tr>
&LT;TD width= "height=" align= "right" > Secret &nbsp;&nbsp; code &nbsp;</td>
<td><input type= "password" value= "" class= "text2" name = "Userpass" id = "Userpassid"/></td>
</tr>
<tr>
&LT;TD width= "height=" align= "right" >&nbsp;</td>
<td><div class= "C4" >
<input type= "Submit" value= "class=" btn2 "/>


Method Two:

function CheckUser () {
var result = document.getElementById ("userid"). Value;
var password = document.getElementById ("Passid"). Value;

if (result = = "") {
Alert ("User name cannot be empty");
return false;
}
if (password = = "") {
Alert ("Password cannot be null");
return false;
}
document.getElementById ("Formid"). Submit ();
}

Form form, need to write ID
<form id= "Formid" method = ' post ' action = ' user_login_submit.action ' >

The button buttons are written as follows:

<input type= "button" value= "" class= "btn2" onclick = "checkUser ();"/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.