Hi,

i have written jsp in which onchange of value in a dropdown another dropdown will appear.
I have used ajax & the entire <select> tag i m passing from action.
as

if( (selectedAccountDivision.equals(""))&& accountDivisions!=null)
	        		{
	        			//System.out.println("inside acc div if block"+selectedAccountDivision);
	        			//out=out+"<table><tr><td class=\"contentBluemain\" width=\"60%\">Select Year<span class=\"contentRedmain\">*</span></td>";
	        			//out="<table><tr><td class=\"contentBluemain\" width=\"60%\" nowrap>Select"+accSubDivTitle+"<span class=\"contentRedmain\">*</span></td><td></td><td></td><td class=\"contentBlack11\"  valign=\"top\">";
	        			out="<table><tr><td class=\"contentBluemain\" width=\"60%\" nowrap>Select "+accDivTitle+"<span class=\"contentRedmain\">*</span></td><td></td><td></td>";
							out=out+"<td class=\"contentBlack11\" width=\"40%\" valign=\"top\"><select name=\"firstLevelAccountDivisions\" class=\"styd\"	onChange=\"onAccountDivisionsChange();\">";
							out=out+"<option value=\"-1\">--Select "+accDivTitle+"--</option>" ;
							out=out+"<option value=\"-2\">All</option>";

....
This drop down is coming fine but
In this new drop down i m calling onchange will call a javascript function as:-

function onAccountDivisionsChange(){
 	alert("inside onAccountDivisionsChange function");
       		if(document.SelectionCriteria.reportToGenerate.options[document.SelectionCriteria.reportToGenerate.selectedIndex].value != '-1')
	        		{
   						 				selectedReportToGenerate =  document.SelectionCriteria.reportToGenerate.options[document.SelectionCriteria.reportToGenerate.selectedIndex].value;
   						 				alert("inside second"+selectedReportToGenerate)
	        						 	document.SelectionCriteria.selectedReportToGenerate.value=selectedReportToGenerate
	     			 }
	     			 var selectedAccountId;
    if(document.SelectionCriteria.firstLevelAccountDivisions!=null)
    {
    alert("inside not null");
     selectedAccountId = document.SelectionCriteria.firstLevelAccountDivisions.options[document.SelectionCriteria.firstLevelAccountDivisions.selectedIndex].value;
      if(document.SelectionCriteria.firstLevelAccountDivisions.selectedIndex==0){
	      return;
	    }
    }
    else
    {
    alert("inside null");
     return;
    }
   
    var selectedProject="";
   
   
    var oldslectedaccountID=document.SelectionCriteria.selectedAccountDivision.value;
    if(selectedAccountId!=oldslectedaccountID)
    {
   	
	document.getElementById("afterAccountDivisionDiv").innerHTML="";
	document.getElementById("afterAccountSubDivisionDiv").innerHTML="";
	document.getElementById("yearDiv").innerHTML="";
	document.getElementById("monthDiv").innerHTML="";
	document.getElementById("extraColumn1Div").innerHTML="";
	document.getElementById("extraColumnDiv").innerHTML="";

    
    }
    document.SelectionCriteria.selectedAccountDivision.value=selectedAccountId;
    	    document.SelectionCriteria.AccName.value=document.SelectionCriteria.firstLevelAccountDivisions.options[document.SelectionCriteria.firstLevelAccountDivisions.selectedIndex].text;
    if(selectedAccountId=="-1" ||selectedAccountId=="-2" )
		 {document.SelectionCriteria.selectedProject.value="";
		 selectedProject="";
		
		// document.getElementById("selectBoxafterSubDivAccount").innerHTML="";
		 
		 }
     else if(!(document.SelectionCriteria.projects==null))
	 {	 
		if(document.SelectionCriteria.projects.options[document.SelectionCriteria.projects.selectedIndex].value != '-1')
		 {	
	
		 	document.SelectionCriteria.selectedProject.value=document.SelectionCriteria.projects.options[document.SelectionCriteria.projects.selectedIndex].value;
		 	 selectedProject=document.SelectionCriteria.projects.options[document.SelectionCriteria.projects.selectedIndex].value;
		 	
		 }
	}
   	if(document.SelectionCriteria.reportToGenerate.options[document.SelectionCriteria.reportToGenerate.selectedIndex].value != '-1')
	        		{
   						 				selectedReportToGenerate =  document.SelectionCriteria.reportToGenerate.options[document.SelectionCriteria.reportToGenerate.selectedIndex].value;
	        						 	document.SelectionCriteria.selectedReportToGenerate.value=selectedReportToGenerate
	      }
	    
	       else
	 {
		alert('Please select Report');
		document.SelectionCriteria.reportToGenerate.focus();
		return false;
	 }
   
    url="/SelectionCriteriaAction.do?selectedAccountDivision="+selectedAccountId+"&reporttype=incident&selectedProject="+selectedProject+"&selectedReportToGenerate="+selectedReportToGenerate;
  
    //Do the Ajax call
    if (window.XMLHttpRequest){ // Non-IE browsers
    alert("inside non IE Browsers");
      req = new XMLHttpRequest();
      //A call-back function is define so the browser knows which function to call after the server gives a reponse back
      req.onreadystatechange = populateBoxAfterAccount;
      try {
      	req.open("GET", url, true); //was get
      } catch (e) {
         alert("Cannot connect to server");
      }
      req.send(null);
    } else if (window.ActiveXObject) { // IE    
      alert("inside IE Browsers");  
      req = new ActiveXObject("Microsoft.XMLHTTP");
      if (req) {
        req.onreadystatechange = populateBoxAfterAccount;
        req.open("GET", url, true);
        req.send(null);
      }
    }
  }

here document.SelectionCriteria.firstLevelAccountDivisions is giving null. Though the 2nd drop down is coming fine.
This is the case only in mozilla.cz in IE its wrkng fyn.
Can any1 tel me what can be the problem or the solution for it?

You have error in the first line of your code so I decided not to go further.

ERROR: extra ')' in if-condition.

Next time please use code tags.

Hi,
I dont find any extra ) in if condition in my code.
Can u tel me where is it?

You have error in the first line of your code so I decided not to go further.

ERROR: extra ')' in if-condition.

Next time please use code tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.