Add value to a textbox dynamically
Jsp

<%@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>
        <script type="text/javascript" language="Javascript" >
            
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Add Course_Subject</title>
<style type="text/css">
            <!--
body {
	background-color: #FFCCFF;
}
.style1 {
	color: #0066FF;
	font-weight: bold;
}
.style2 {font-size: 18px}
.style17 {	font-family: "Monotype Corsiva";
	font-size: 24px;
	font-weight: bold;
	font-style: italic;
	color: #6633CC;
}
.style19 {color: #000099}
.style21 {color: #000099; font-weight: bold; }
-->
</style>


    </head>
    <body>
        <jsp:include page="Log_Admin.jsp"/><br/>
        <form action="" method="post" name="form1" id="form1">
        <table width="46%" height="43" border="3" bgcolor="##CCCC99" align="center">
            <tr>
                <td width="85%" align="center" bgcolor="#FFFF99"><label><span class="style17">Course and Subject Information</span></label></td>
            </tr>
            
            <tr><td>
                <table width="666" height="207" border="0" align="center" bordercolor="#F0F0F0" bgcolor="#CCCC99" >
                    <tr>
                        <td width="186" height="46" align="left"><div align="left"><span class="style19">
                        <label><strong>Coourse ID</strong></label>
                        </span></div></td>
                        <td><label>
                            <select name="cid" size="1" id="cid" align="left" onclick="loaadCourseName()">
                            <option selected="selected">None</option>
                            <option>C001</option>
                            <option>C002</option>
                            <option>C003</option>
                            <option>C004</option>
                            <option>C005</option>
                            <option>C006</option>
                            <option>C007</option>
                            <option>C008</option>
                            <option>C009</option>
                            <option>C010</option>
                            </select>
                        </label></td>
                        <td width="186" height="46" align="left"><div align="left"><span class="style19">
                        <label><strong>Coourse Name</strong></label>
                        </span></div></td>
                        <td width="310" align="left"><input name="cname" type="text" id="cname" size="25" maxlength="50" /></td>
                    </tr>
                    
                    <tr>
                        <td width="186" height="46" align="left"><div align="left"><span class="style19">
                        <label><strong>Subject ID</strong></label>
                        </span></div></td>
                        <td><label>
                            <select name="sid" size="1" id="sid" align="left">
                            <option selected="selected">None</option>
                            <option>S01</option>
                            <option>S02</option>
                            <option>S03</option>
                            <option>S04</option>
                            <option>S05</option>
                            <option>S06</option>
                            <option>S07</option>
                            <option>S08</option>
                            <option>S09</option>
                            <option>S10</option>
                            </select>
                        </label></td>
                        <td width="186" height="46" align="left"><div align="left"><span class="style19">
                        <label><strong>Subject Name</strong></label>
                        </span></div></td>
                        <td width="310" align="left"><input name="sname" type="text" id="sname" size="25" maxlength="50" /></td>
                    </tr>
                    
                    <tr>
                        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="save" type="submit" id="save" value="Save" onclick="validate(this.form)"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="reset" type="reset" id="reset" value="Reset" /></td>
                    </tr>
                </table>
            </td></tr>
        </table>
    </form>
    </body>
</html>

Servlet

package DBCon;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
/**
 *
 * @author Nayan
 */
public class searchCourseName extends HttpServlet {
   
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String cname=null,courseid;
        try
        {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost/online_exam?"+"user=root&password=pass");
            Statement stmt=con.createStatement();
            
            courseid=request.getParameter("cid");
            ResultSet rs=stmt.executeQuery("select course_name from course where course_id='"+courseid+"'");
            
            while(rs.next())
            {
                cname=rs.getNString("course_name");
                //String s=rs.getString(1);
            }
            request.getSession().setAttribute("courseName",cname);
            //RequestDispatcher requestDispatcher=getServletContext().getRequestDispatcher("http://localhost:8080/ONLINEEXAMINATION/removeCourse2.jsp");
            //requestDispatcher.forward(request,response);

        }
         catch(Exception e) { 
            out.println("<h1>"+e.getStackTrace()+"</h1>");
        }
    } 

    // <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
    */
    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
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}


Now when i select an item in the combobox cid i want to display the corresponding courname in the cname textbox. For this what should i've to write in my coding.Thanks.
Add value to a textbox dynamically
===

Jsp

<%@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>
        <script type="text/javascript" language="Javascript" >
            
        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Add Course_Subject</title>
<style type="text/css">
            <!--
body {
	background-color: #FFCCFF;
}
.style1 {
	color: #0066FF;
	font-weight: bold;
}
.style2 {font-size: 18px}
.style17 {	font-family: "Monotype Corsiva";
	font-size: 24px;
	font-weight: bold;
	font-style: italic;
	color: #6633CC;
}
.style19 {color: #000099}
.style21 {color: #000099; font-weight: bold; }
-->
</style>


    </head>
    <body>
        <jsp:include page="Log_Admin.jsp"/><br/>
        <form action="" method="post" name="form1" id="form1">
        <table width="46%" height="43" border="3" bgcolor="##CCCC99" align="center">
            <tr>
                <td width="85%" align="center" bgcolor="#FFFF99"><label><span class="style17">Course and Subject Information</span></label></td>
            </tr>
            
            <tr><td>
                <table width="666" height="207" border="0" align="center" bordercolor="#F0F0F0" bgcolor="#CCCC99" >
                    <tr>
                        <td width="186" height="46" align="left"><div align="left"><span class="style19">
                        <label><strong>Coourse ID</strong></label>
                        </span></div></td>
                        <td><label>
                            <select name="cid" size="1" id="cid" align="left" onclick="loaadCourseName()">
                            <option selected="selected">None</option>
                            <option>C001</option>
                            <option>C002</option>
                            <option>C003</option>
                            <option>C004</option>
                            <option>C005</option>
                            <option>C006</option>
                            <option>C007</option>
                            <option>C008</option>
                            <option>C009</option>
                            <option>C010</option>
                            </select>
                        </label></td>
                        <td width="186" height="46" align="left"><div align="left"><span class="style19">
                        <label><strong>Coourse Name</strong></label>
                        </span></div></td>
                        <td width="310" align="left"><input name="cname" type="text" id="cname" size="25" maxlength="50" /></td>
                    </tr>
                    
                    <tr>
                        <td width="186" height="46" align="left"><div align="left"><span class="style19">
                        <label><strong>Subject ID</strong></label>
                        </span></div></td>
                        <td><label>
                            <select name="sid" size="1" id="sid" align="left">
                            <option selected="selected">None</option>
                            <option>S01</option>
                            <option>S02</option>
                            <option>S03</option>
                            <option>S04</option>
                            <option>S05</option>
                            <option>S06</option>
                            <option>S07</option>
                            <option>S08</option>
                            <option>S09</option>
                            <option>S10</option>
                            </select>
                        </label></td>
                        <td width="186" height="46" align="left"><div align="left"><span class="style19">
                        <label><strong>Subject Name</strong></label>
                        </span></div></td>
                        <td width="310" align="left"><input name="sname" type="text" id="sname" size="25" maxlength="50" /></td>
                    </tr>
                    
                    <tr>
                        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="save" type="submit" id="save" value="Save" onclick="validate(this.form)"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="reset" type="reset" id="reset" value="Reset" /></td>
                    </tr>
                </table>
            </td></tr>
        </table>
    </form>
    </body>
</html>

Servlet

package DBCon;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
/**
 *
 * @author Nayan
 */
public class searchCourseName extends HttpServlet {
   
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String cname=null,courseid;
        try
        {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost/online_exam?"+"user=root&password=pass");
            Statement stmt=con.createStatement();
            
            courseid=request.getParameter("cid");
            ResultSet rs=stmt.executeQuery("select course_name from course where course_id='"+courseid+"'");
            
            while(rs.next())
            {
                cname=rs.getNString("course_name");
                //String s=rs.getString(1);
            }
            request.getSession().setAttribute("courseName",cname);
            //RequestDispatcher requestDispatcher=getServletContext().getRequestDispatcher("http://localhost:8080/ONLINEEXAMINATION/removeCourse2.jsp");
            //requestDispatcher.forward(request,response);

        }
         catch(Exception e) { 
            out.println("<h1>"+e.getStackTrace()+"</h1>");
        }
    } 

    // <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
    */
    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
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}


Now when i select an item in the combobox cid i want to display the corresponding courname in the cname textbox. For this what should i've to write in my coding.Thanks.