title: How do I reset the value from the parameter passed by URL from Javascript in JSP
body: <p>This is my first question ever in this website which I hope I can explain it well. I did find the same problem but mostly in PHP and I don't really understand (e.g- <a href="https://stackoverflow.com/questions/7171099/how-to-replace-url-parameter-with-javascript-jquery">How to replace url parameter with javascript/jquery?</a>). Here my explaination:</p>
  
  <p>I have a function in Javascript (in page testStudentFile.jsp):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;script language="javascript"&gt;
  
  function onParamChange(){
  
   var thisForm = document.frmParam;
   
   var strBranch = thisForm.reqBranch.value;
   var strFaculty = thisForm.reqFaculty.value;
   var strCourse = thisForm.reqCourse.value;
   
   location.href ="testStudentFile.jsp?reqBranch="+strBranch+"&amp;reqFaculty="+strFaculty+"&amp;reqCourse="+strCourse;
  }   
  
   &lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Which get the value from here (and post at the same page):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form name="frmParam" action="testStudentFile.jsp" method="POST"&gt;
        
  &lt;tr&gt;
    &lt;td width="20%"&gt;&lt;strong&gt;Branch:&lt;/strong&gt;&lt;/td&gt;
    &lt;td&gt;
      &lt;%renderDropDownList2(out, "reqBranch",  arrBranch,  requestValue.strBranch,"onchange=\"onParamChange()\"");%&gt;&lt;%=strBranchDesc%&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td width="20%"&gt;&lt;strong&gt;Faculty:&lt;/strong&gt;&lt;/td&gt;
    &lt;td&gt;
      &lt;%renderDropDownList2(out, "reqFaculty",  arrFaculty,  requestValue.strFaculty,"onchange=\"onParamChange()\"");%&gt;&lt;%=strFacultyDesc%&gt;
    &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr align="left"&gt;
    &lt;td&gt;&lt;strong&gt;Course: &lt;/strong&gt;&lt;/td&gt;
    &lt;td&gt;
      &lt;%renderDropDownList2(out, "reqCourse", arrCourse, requestValue.strCourse,"onchange=\"onParamChange()\"");%&gt;&lt;%=strCourseDesc%&gt;
    &lt;/td&gt;
  &lt;/tr&gt;  
  &lt;tr align="left"&gt;
    &lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&lt;strong&gt;&lt;%out.print(arrStudent.size() + " students");%&gt;&lt;/strong&gt;  
    &lt;/td&gt;
  &lt;/tr&gt; 
  &lt;tr&gt;
    &lt;td&gt;&lt;/td&gt;
    &lt;td&gt;&lt;input name="reqSearch" class="iform" type="submit" value="Search"&gt;&lt;/td&gt;
  &lt;/tr&gt;   
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>And the data was retrieved from the method void that called data using sql query. Example one of the query:-</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>  &lt;%!
  public void populateBranch(JspWriter out, Connection ConnTC, ArrayList arrBranch)throws Exception{
  
   String sqlSelect =  " SELECT DISTINCT branch FROM university"+
        " WHERE active='Y'"+
        " AND branch='PK'"+
        " OR branch='ZZ'";
   //out.print(sqlSelect);
   PreparedStatement stmtSelect = ConnTC.prepareStatement(sqlSelect);
   ResultSet rsSelect = stmtSelect.executeQuery();
   while(rsSelect.next()){
    String strBranch  = getValue(rsSelect.getString("fbrncd"));
    arrBranch.add(strBranch);
    } 
   rsSelect.close();
   stmtSelect.close();
  }
     %&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here is my problem:</p>
  
  <p>When I choose PK for branch, it will automatically list down the related faculties and next the related courses from the dropdownlists, but when I choose ZZ, the faculty and course choosen from PK branch didnt reset to the default(empty) before I can choose a faculty and a course for branch ZZ. How do I reset the dropdownlist (without reset button) to the default in the value of the parameter of the URL as stated in the Javascript above whenever the branch changed?</p>
  
  <p>(Example)</p>
  
  <p>From--> <a href="http://xxx.xxx.xx.x/portal/testApp/request/testStudentFile.jsp?reqBranch=PK&amp;reqFaculty=FAS&amp;reqCourse=AV" rel="nofollow noreferrer">http://xxx.xxx.xx.x/portal/testApp/request/testStudentFile.jsp?reqBranch=PK&amp;reqFaculty=FAS&amp;reqCourse=AV</a></p>
  
  <p>To--> <a href="http://xxx.xxx.xx.x/portal/testApp/request/testStudentFile.jsp?reqBranch=ZZ&amp;reqFaculty=&amp;reqCourse=" rel="nofollow noreferrer">http://xxx.xxx.xx.x/portal/testApp/request/testStudentFile.jsp?reqBranch=ZZ&amp;reqFaculty=&amp;reqCourse=</a></p>
  
  <p>Warm Regards &lt;3,</p>
  
  <p>Eja ;-)</p>