Click here to Skip to main content
15,749,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How do I change drop down list content based on radio button click.
my try :

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

 * Servlet implementation class Tes
public class Tes extends HttpServlet {
	private static final long serialVersionUID = 1L;
     * @see HttpServlet#HttpServlet()
    public Tes() {
        // TODO Auto-generated constructor stub

	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		HttpSession sess = request.getSession(true);
		int id = 5;
		sess.setAttribute("id", id);
		PrintWriter outid = response.getWriter();  
	    	+"<script language='javascript'>"
	    		+"var current = false;"
	    		+"function onChange()"
	    		+"var rad = document.getElementById('radIn').checked;"
	    			+"if(rad == current)"
	    			+"current = rad;"
	    			+"var array = rad ? ['in1','in2','in3','in4','in5'] :"
	    			+"var sel = document.getElementById('dropDown');"
	    			+"sel.innerHTML = '';"
	    			+"var opt;"
	    			+"for each(var k in array)"
	    				//alert(k + ' asdsd');
	    				+"opt = document.createElement('option');"
	    				+"opt.innerHTML = k;"
	    +"<body >"
	    	+"<input type='radio' value='in' name='campus' />"
	    	+"<label for='radIn'>In Campus</label>"
	    +"<br />"
	    +"<input type='radio' value='out' name='campus' />"
	    	+"<label for='radOut'>Out Campus</label>"
	    	+"<br />"
	    	+"<select id='dropDown'/>"

	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);

Updated 10-Nov-15 15:18pm
Wombaticus 10-Nov-15 17:54pm    
It's better to post your code here. No-one wants to click on a link that could be to anything...
Mohibur Rashid 10-Nov-15 21:20pm    
You can change list content onClick event
First delete the current content and
write the changes.

If the list comes from your server then you should consider AJAX
Mohibur Rashid 11-Nov-15 2:36am    
First of all: no, I am not going to do that. I am not going to fix your code.
The reason is you didn't do anything.

go to google search for "Javascript event handler"

document.write statement in SCRIPT tag. document.write will destroy your current window and print 1

There is some Javascript code inside your html tags. Pointless

And follow tutorial please. You know nothing about html or Javascript

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900