Sei sulla pagina 1di 5

Form validation example ...

part 1
<HTML><HEAD> <TITLE>Account authorization</TITLE> <SCRIPT LANGUAGE="JAVASCRIPT"> function validateFormData() { var message = ""; if (document.AccountForm.Name.value.length == 0) { message = message + "Name field cannot be left blank!\n"; } if (document.AccountForm.Password.value.length < 8) { message = message + "Password needs to be atleast 8 chars!\n"; } if (document.AccountForm.Trans.checked == true) { if (document.AccountForm.TransPwd.value.length < 4) { message = message + "Trans pwd needs to be atleast 4 chars!\n"; } } if ( message.length > 0 ) { alert( message ); return false; } else { return true; } }

Form validation example ... part 2


function resetFormData() { document.AccountForm.Name.value = ""; document.AccountForm.Password.value = ""; document.AccountForm.TransPwd.value = ""; } function showTransPwd() { if (document.AccountForm.Trans.checked == false) { document.AccountForm.TransPwd.style.display="none"; } else { document.AccountForm.TransPwd.style.display=""; } }

Form validation example ... part 3


</SCRIPT></HEAD> <BODY onLoad="document.CardForm.HoldersName.focus()"> <FORM NAME="AccountForm" action="destination.jsp" onsubmit="return validateFormData();" onreset="return resetFormData();"> Name: <INPUT TYPE="TEXT" NAME="Name"><BR> Password: <INPUT TYPE="PASSWORD" NAME="Password" SIZE="12" MAXLENGTH="12"><BR> Use Trans Pwd: <input type="checkbox" onClick="showTransPwd()" name="UseTransPwd" id="Trans" /> <INPUT TYPE="PASSWORD" NAME="TransPwd" SIZE="12" MAXLENGTH="12"><BR> <INPUT TYPE="Submit" VALUE="Submit"> <INPUT TYPE="Reset" VALUE="Reset"> </FORM> </BODY> </HTML>

Form validation example


<HTML><HEAD> <TITLE>Account authorization</TITLE> <SCRIPT LANGUAGE="JAVASCRIPT"> function validateFormData() { var message = ""; if (document.AccountForm.Name.value.length == 0) { message = message + "Name field cannot be left blank!\n"; } if (document.AccountForm.Password.value.length < 8) { message = message + "Password needs to be atleast 8 characters!\n"; } if (document.AccountForm.Trans.checked == true) { if (document.AccountForm.TransPwd.value.length < 4) { message = message + "Transaction password needs to be atleast 4 characters!\n"; } } if ( message.length > 0 ) { alert( message ); return false; } else { return true; } } function resetFormData() { document.AccountForm.Name.value = ""; document.AccountForm.Password.value = ""; document.AccountForm.TransPwd.value = ""; document.AccountForm.TransPwd.style.display="none"; } function showTransPwd() { if (document.AccountForm.Trans.checked == false) { document.AccountForm.TransPwd.style.display="none"; } else { document.AccountForm.TransPwd.style.display=""; } } </SCRIPT></HEAD> <BODY onLoad="document.CardForm.HoldersName.focus()"> <FORM NAME="AccountForm" action="destination.jsp" onsubmit="return validateFormData();" onreset="return resetFormData();"> Name: <INPUT TYPE="TEXT" NAME="Name"><BR> Password: <INPUT TYPE="PASSWORD" NAME="Password" SIZE="12" MAXLENGTH="12"><BR> Use Trans Pwd: <input type="checkbox" onClick="showTransPwd()" name="UseTransPwd" id="Trans" /> <INPUT TYPE="PASSWORD" NAME="TransPwd" SIZE="12" MAXLENGTH="12" style="display:none"><BR> <INPUT TYPE="Submit" VALUE="Submit"> <INPUT TYPE="Reset" VALUE="Reset"> </FORM> </BODY> </HTML>

Assignment
Modify above example to take: Name of the borrower Book number Account number of borrower, if available: use checkbox and input field

Potrebbero piacerti anche