How To Execute Javascript in .jsp Page
Steps :-
- You can execute javascript by writing it internally in .jsp page, code is as follow....
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>JSP Page</title>
- <script> // Starting tag of java script should be declared in head portion of .jsp page..
- function fun()
- {
- if(document.f1.t1.value=="")
- {
- alert("PLEASE ENTER NAME");
- }
- else if(document.f1.t2.value=="")
- {
- alert("PLZ FILL PASSWORD FIELD ");
- }
- else
- {
- alert("yuppy Suusesfully done ");
- }
- }
- </script>
- </head>
- <body>
- <form name="f1" method="get" action="" onSubmit="return fun()"> // onSubmit attribute of form is compulsorily writtern .....with value (return keyword & name of function )
- <table border="1" bgcolor="silver" ALIGN="CENTER">
- <tr>
- <td>NAME:</td>
- <td><input type="text" name="t1"/></td>
- </tr>
- <tr>
- <td>PASSWORD:</td>
- <td><input type="password" name="t2"/></td>
- </tr>
- <tr>
- <td align="center"><input type="submit" name="btnsub" value="Submt"/></td>
- <td><input type="reset" value="Reset">
- </tr>
- </table>
- </form>
- </body>
Note: for executing the .jsp code you must have to set the server .....and default browser in netbeans 7.1.2 IDE thnx ......