|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Validation - need help!
Hi there, im learning java, so forgive me if this sounds very n00bish, and help would be greatly appreciated :P
im looking to a registration for my website for users to log in, and some feilds are required <form name="createcustomer" action="cprocess.asp" method="post"> <input name="fname" type="text" size="40"> * required <input name="lname" type="text" size="40"> * required <input name="company" type="text" size="40"> <input name="email" type="text" size="40"> * required <input name="address" type="text" size="40"> <input name="suburb" type="text" size="40"> <input name="postcode" type="text" size="40"> <input name="state" type="text" size="40"> <input name="phone" type="text" size="40"> * required <input name="fax" type="text" size="40"> <input name="mob" type="text" size="40"> <input type="checkbox" name="checkbox" value="checkbox"> * required - to agree with some terms how can i validate this using java? |
|
#2
|
|||
|
|||
|
the information given is not complete however i 'll try to my best as it looks to me .i am assuming that you are using jsp.because java alone could not be used for web applications.
however if you are using jsp even then you would be requing client side scripting language like javascript to do the validation . you will be requiring to do the following you can place this opening script and closing tag any where in the html file but try to keep it before the form starts . <script> function chk() { /*put all your validation code here return false if an error is found else return true on the last line of the function. an example is shown so that the user could not leave his name empty*/ if(win.form.fname.value=="") { alert("Please enter your fname"); return false; } else if(win.form.lname.value=="") { alert("Please enter your lname"); return false; } else if(win.form.email.value=="") { alert("Please enter your email return false; } else if(win.form.phone.value=="") { alert("Please enter your phone"); return false; } return true; } </script> now in the form tag add an attribute named onSubmit like <Form name="" action="" onsubmit="return chk()"> if there is an error generated by the chk() function the user will be forced to make corrections and the form will not be submitted. |
|
#3
|
||||
|
||||
|
Java or JavaScript??
Are you dealing with public static void main(String args[]) {} or <script> in your syntax?? |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Validation - need help! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|