How to clear a data in dynamic combo box?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jerald m
    New Member
    • Dec 2010
    • 28

    #1

    How to clear a data in dynamic combo box?

    Hi,

    In my Form(JSP) using ajax i done dynamic combo box.3 combo box is in my Form.

    In database country,State,A rea is available

    Country-->India,Russia,A ustralia
    State---> TN,Del,LL for India.HH,SO for Russia.JO,KO for Australia

    Area --->Aa,Bb for TN....

    Now if i select Russia in 1st combo box the appropriate state is loading.

    But India having three state and other two country's having two state only.

    But now my problem is if the user forgottenly select India and in 2nd combo box appropriate state are coming, with the same page the user select Russia mean's 2nd combo box dynamically generating but Russia has two state only right but it showing three state. the first time selected by the user India's third state is not disappearing. i want to delete that Please Help me



    below code will load at on OnChange
    Code:
    function loadProject()
    {
    
     xmlhttp=GetXmlHttpObject();
    
      if (xmlhttp==null)
      {
       alert ("Your browser does not support Ajax HTTP");
       return;
      }
      
        var project = document.getElementById("Project").value;
        //alert(project);
    	var url="Project.jsp";
        url=url+"?Project="+project;
    	//alert(url);
        xmlhttp.onreadystatechange=Output;
        xmlhttp.open("GET",url,true);
        
    	xmlhttp.send(null);
    }
    
    
    function Output()
    {
      if (xmlhttp.readyState==4)
      {
    var result = xmlhttp.responseText;
    	var s = result.split(" ");
    			var indx =1;
    						for(indx=1; indx < s.length;indx++)
    	{
    	document.frm.Stage.options[indx] = new Option(s[indx]);
    			
    			}
    			
    	  }
    
    }
    function GetXmlHttpObject()
    {
        if (window.XMLHttpRequest)
        {
           return new XMLHttpRequest();
        }
        if (window.ActiveXObject)
        {
          return new ActiveXObject("Microsoft.XMLHTTP");
        }
     return null;
    }

    Code:
    <select name="Project" id="Project" onChange="return loadProject();">
    
    <option value="-1">---Please select---</option>
    
    <%while(rs1.next())
    {
    %>
    <option value="<%=rs1.getString(1)%>"><%=rs1.getString(1)%> </option>
    <%}%>
    <%
    	rs1.close();
    %>

    i need to clear cache at the time in my form while Onchange event happening...
    please help MEEE....
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You could do 2 things:
    1. remove all current options before selecting next option. This can usually be achieved with a single line: sel.options.len gth = 0;
    2. remove all remaining options.

    Comment

    Working...