I have three buttons(input type="submit") on my LogOn Screen which expects a user to input the name and password in these 2 textboxes provided for authentication. The buttons are 1.see home page button 2.see change password screen button 3.exit logon screen button I am checking for empty fields (in username and password fields) if any popup alert(message).But the checking of empty fields should not happen on clicking the exit button.It should happen only when the button 1 or button 2 is clicked. the exit button should be handled by the action ="/servlet/Controllerservlet" By help, Codes are welcomed.Thanks.
Gabriel It looks like all three of your buttons are of the same format, ie they look like this: <input type=submit value=xxx> If thats true then anytime you click on one of the buttons the form is submitted. To change the functionality of one of the buttons make a plain button then add the functionality to the onclick method. This might work for your exit button: <input type=button value='Exit Logon' onclick='window.location("/servlet/Controllerservlet")> And then something similiar for your 'see password change screen' button. to check for empty fields, this code works well:
Just pass it the string your checking and it returns true or false. hope that helps Dave
</tr> <tr> <input type='button' name='exit' onclick='window.location("/servlet/ControllerServlet");' value="E X I T " </td> </tr>
</table> </form> </html> Please, an urgent response will be appreciated. Note: Dave, i donot really know the blank checker function will be used. Besides, aside from the Logon screen i have loads of pages(JSP) which i need to validate and this pages have say minimum 10 fields(compulsory) and few optional ones. So , i need to get the validation concept very clear.
Question. At the moment using the above script pops up the alert on clicking the the ENTER and CHANGE-PASSWORD button + empty fields, Which am happy with.But , on clicking the EXIT button,It pops up a runtime error ,saying "Property or function CANNOT BE USED ON THIS OBJECT".I am confused. NOTE: Is it possible to go straight to the "ExitPage.jsp" without going through the form handler in the action ="controllerServlet".If YES,Pls how is it done. Please help!!! Codes are very welcomed.Thanks.
[This message has been edited by Gabriel Fox (edited November 15, 2001).]
For your exit page you can just enter the URL: window.location = "exitPAge.jsp"; And you'll go right to it, I'm not that familiar with servlets yet so I'm not sure what the controllerServlet does. Hope this helps Dave
Nice one !!! You made my Day again Dave .Cheers!!! I saw the window.loaction=----- while struggling with my JScript book ,but i was not too ready to read more on it's use. Instead, i used the : onclick="location.replace('NameOfPage.jsp');" which took me straight to the NameOfPage.jsp WITHOUT GOING THRU the action="FormHandler"(that worked fine). NOTE: I am developing an application based on Java Technology(JSPs,Servlets,JavaBeans) using model-2 framework and i realised i need enough front end processing (e.g form validation etc) to make life easier. After testing the posted script : i confirmed an invalid user can go pass the page(not necessarily logon) using just a space character or this character: ` in either textfields. Question:1 How do we guard against going pass the logon form (screen) using any strange character aside from whitespace i.e.' ' 2. Can you please suggest the JScript standard validation technique for a from with say 10 required fields and 4 optional ones.somes of the fields are :address lines 1-4,phone,fax, e-mail,amount(currency),pain text. Codes will be highly appreciated as well any nice source-code website. Cheers
Gabriel Here is a little piece of code that will check if a string is all whitspace, you can easily change it to check for strange characters too.
To do this I start all of the required fields with an r, that way you dont bother checking things like the submit button and other things. hope that helps you out Dave