Showing posts with label jsp. Show all posts
Showing posts with label jsp. Show all posts

Tuesday, March 28, 2017

Javascript to get drop down selected value

Java script to get drop down selected value.

 <!DOCTYPE html>  
 <html>  
 <head>  
 <style>  
 #myDIV {  
   width: 100%;  
   padding: 50px 0;  
   text-align: center;  
   background-color: lightblue;  
   margin-top:20px;  
 }  
 </style>  
 </head>  
 <body>  
 <p>Java script to get dropdown selected value :</p>  
 <select onchange="myFunction()" id="priority">  
 <option></option>  
 <option>1</option>  
 <option>2</option>  
 <option>3</option>  
 </select>  
 <p id="prioritydefination"></p>  
 <p><b>Note:</b> The element will not take up any space when the display property set to "none".</p>  
 <script>  
 function myFunction() {  
   var priority = document.getElementById("priority").value;  
   if(priority === ''){  
        document.getElementById("prioritydefination").innerHTML = "You selected: " + priority ;  
   }else if(priority == 1){  
         document.getElementById("prioritydefination").innerHTML = "You selected: " + priority ;  
       }else if(priority == 2){  
             document.getElementById("prioritydefination").innerHTML = "You selected: " + priority ;  
        }else if(priority == 3){  
        document.getElementById("prioritydefination").innerHTML = "You selected: " + priority ;  
   }  
 }  
 </script>  
 </body>  
 </html>  
 
Output:
 

Monday, November 5, 2012

Calculator useing jsp

Cal.jsp  
 <%--   
   Document  : Cal  
 --%>  
 <%@page contentType="text/html" pageEncoding="UTF-8"%>  
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
   "http://www.w3.org/TR/html4/loose.dtd">  
 <html>  
   <head>  
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
     <title>Calculator</title>  
   </head>  
   <body>  
     <form metod="get" action="Cal1.jsp">  
     Value1:<input type="text" name="v1"/><br/>  
     Value2:<input type="text" name="v2"/><br/>  
     Opration:<select name="op">  
     <option>+</option>  
     <option>-</option>  
     <option>*</option>  
     <option>/</option>  
     </select><br/>  
     <input type="submit" name="b" value="ok"/>  
   </form>  
   </body>  
 </html>  


 Cal1.jsp  
 <%--   
   Document  : Cal1  
 --%>  
 <%@page contentType="text/html" pageEncoding="UTF-8"%>  
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
   "http://www.w3.org/TR/html4/loose.dtd">  
 <html>  
   <head>  
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
     <title>JSP Page</title>  
   </head>  
   <body>  
     <%! int ans; %>  
     <% int s=Integer.parseInt(request.getParameter("v1"));  
     int r=Integer.parseInt(request.getParameter("v2"));  
     String op1=request.getParameter("op");  
       if(op1.equals("+")){  
       ans=s+r;  
       }  
       if(op1.equals("-")){  
       ans=s-r;  
       }  
       if(op1.equals("*")){  
       ans=s*r;  
       }  
       if(op1.equals("/")){  
        ans=s/r;  
       }%>  
       <h1> answer is : <%=ans%> </h1>   
   </body>  
 </html>  







Saturday, October 13, 2012

how to create dropdown list in java swing

 Dropdownlist.java   
 import java.io.IOException;  
 import java.io.PrintWriter;  
 import javax.servlet.ServletException;  
 import javax.servlet.http.HttpServlet;  
 import javax.servlet.http.HttpServletRequest;  
 import javax.servlet.http.HttpServletResponse;  
 public class Dropdownlist extends HttpServlet {  
   /**   
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.  
    * @param request servlet request  
    * @param response servlet response  
    * @throws ServletException if a servlet-specific error occurs  
    * @throws IOException if an I/O error occurs  
    */  
   protected void processRequest(HttpServletRequest request, HttpServletResponse response)  
       throws ServletException, IOException {  
     response.setContentType("text/html;charset=UTF-8");  
     PrintWriter out = response.getWriter();  
     try {  
       out.println("<html>");  
       out.println("<head>");  
       out.println("<title>Servlet Dropdownlist</title>");   
       out.println("</head>");  
       out.println("<body>");  
       out.println("<h1>Servlet Dropdownlist at " + request.getContextPath () + "</h1>");  
       out.println("<form method='get'>");  
       out.println("<select name='s'>");  
       for(int i=0;i<10;i++){  
         out.println("<option name="+i+">"+i+"</option>");  
       }  
       out.println("</select>");  
       out.println("<input type='submit'>");  
       out.println("</form>");  
       out.println("</body>");  
       out.println("</html>");  
       int b=Integer.parseInt(request.getParameter("s"));  
       for(int j=1;j<=10;j++){  
         out.print(b+"*"+j+"=");  
         out.println(j*b);  
         out.println("<br>");  
       }  
     } finally {        
       out.close();  
     }  
   }  
 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">  
   /**   
    * Handles the HTTP <code>GET</code> method.  
    * @param request servlet request  
    * @param response servlet response  
    * @throws ServletException if a servlet-specific error occurs  
    * @throws IOException if an I/O error occurs  
    */  
   @Override  
   protected void doGet(HttpServletRequest request, HttpServletResponse response)  
       throws ServletException, IOException {  
     processRequest(request, response);  
   }  
   /**   
    * Handles the HTTP <code>POST</code> method.  
    * @param request servlet request  
    * @param response servlet response  
    * @throws ServletException if a servlet-specific error occurs  
    * @throws IOException if an I/O error occurs  
    */  
   @Override  
   protected void doPost(HttpServletRequest request, HttpServletResponse response)  
       throws ServletException, IOException {  
     processRequest(request, response);  
   }  
   /**   
    * Returns a short description of the servlet.  
    * @return a String containing servlet description  
    */  
   @Override  
   public String getServletInfo() {  
     return "Short description";  
   }// </editor-fold>  
 }