Submit onchange doesn't work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • colyn7
    New Member
    • Aug 2008
    • 8

    Submit onchange doesn't work

    I really can't see what's wrong in my code... the submit() onChange doesn't work..

    I've tried..

    Code:
    <select name="ddlTestCenter" id="ddlTestCenter" style="width:180px" onChange="this.form.submit();">
    it doesn't work...

    Code:
    <input type="hidden" name="hiddenopt" value="secret"> <select name="list" onChange="document.forms['try'].submit();">
    this one work on my test page.. but it didn't work when i embed it on my project..

    here is the complete code of my webApp.. I'll truly appreciate and be grateful of whatever help you'll be able to give.. thanks in advance...

    <%@ page import="java.sq l.*" %>
    <%@ page import="java.io .*" %>
    <%@ page import ="java.util. *" %>
    <%@ page import="java.te xt.*" %>
    <%@page import ="java.lang. *" %>


    [HTML]<html>
    <head>

    <LINK href="Admin/css/format.css" type="text/css" rel="stylesheet ">

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>WBITE Index</title>
    <table width="100%" bgcolor="#FFFFF F">
    <tr> <td height="10"></td></tr>
    <tr>
    <td width="159" height="45" align="right">
    <img src="Admin/Images/logor.gif" width="159" height="45" /></td>
    <td width="100%" valign="bottom" align="left">
    <img align="bottom" src="Admin/Images/header.gif" alt="header" />
    </td>
    </tr>
    <tr>
    <td colspan="2" align="center" width="100%" background="Adm in/Images/lineB.gif" height="23" valign="top">
    </td>
    </tr>


    </table>
    <script language="Javas cript" type="text/javascript">
    function matchPassword(p assword,otherpa ssword)
    {
    document.getEle mentById("passw ord_match_statu s").style.displ ay="";
    if (password == otherpassword)
    {
    document.getEle mentById("passw ord_match_statu s").style.displ ay="<img src="../Images/ImageButtons/approve_ovr.gif "> Passwords Match";
    }

    else {
    document.getEle mentById("passw ord_match_statu s").style.displ ay = "<img src="../Images/ImageButtons/disapprove_ovr. gif"> Passwords Do Not Match";
    }
    }


    function reloadForm(){
    document.regExa minee.action = "regExaminee.js p";
    document.regExa minee.submit();
    }


    function populate(){

    ddlTestCenter = document.getEle mentById("regEx aminee");
    ddlTestCenter = "ddlExamSchedul e.do";
    ddlTestCenter.s ubmit();

    }

    </script>
    </head>

    <body>

    <!--header-->
    <table width="100%">
    <!--DWLayoutTable-->
    <tr>
    <td width="400" rowspan="4" align="center" valign="top">
    <table width="400" cellpadding="3" cellspacing="0" bgcolor="#FEE9C B">


    <input type="hidden" name="_submitte d" value="1">
    <input type="hidden" name="next" value="/">
    <input type="hidden" name="tzoffset" value="">
    <tr>
    <td colspan="5" valign="top" bgcolor="#FBEFE F" align="center" width="400">
    <table width="400" bgcolor="#FEE9C B" border="2">
    <!--DWLayoutTable-->
    <tr>
    <td height="20" colspan="5" align="left" style="color:#F FFFFF; font-weight:bold; background-color:#641A00"> Register Examinee </td>
    </tr>
    <tr>
    <td align="center" valign="top" width="400" >


    <form name="regExamin ee" method="post" action="regExam inee.jsp" >

    <!--Start of Registration Form-->
    <%
    String testCenter = request.getPara meter("ddlTestC enter");
    String driver = "com.mysql.jdbc .Driver";
    String url = "jdbc:mysql ://192.168.0.9:330 6/WBITE?user=root ";
    Connection con = null;
    ResultSet rs = null;
    ResultSet rs2 = null;
    Statement stmt = null;
    con = DriverManager.g etConnection(ur l);
    stmt = con.createState ment();
    %>
    <table cellpadding="3" bgcolor="#FEF9E 9" width="400">
    <tr>
    <td style="text-align:right!imp ortant;width:13 0px">Test Center:</td>
    <td>
    <input type="hidden" name="hiddenopt " value="secret">

    <select name="ddlTestCe nter" id="ddlTestCent er" style="width:18 0px" onChange="this. form.submit();" >

    <option value="javascri pt:void(0)">- Test Center -</option>
    <%

    try {
    rs = stmt.executeQue ry("CALL `WBITE`.`uspSel ectTestCenter`( )");
    while (rs.next()) {
    if(testCenter == rs.getString(1) ){
    %>
    <option name="ddlTestCe nterOption" id="ddlTestCent erOption" value="<%=rs.ge tString(1)%>" selected="selec ted"> <%=rs.getString (1)+" ("+ rs.getString(2) +")"%></option>
    <%
    }

    else
    {
    %>
    <option name="ddlTestCe nterOption" id="ddlTestCent erOption" value="<%=rs.ge tString(1)%>"> <%=rs.getString (1)+" ("+ rs.getString(2) +")"%></option>
    <%
    }
    }
    } catch (Exception e) {
    System.out.prin tln(e);
    }
    %>
    </select>
    </td>
    </tr>
    <tr>
    <td style="text-align:right!imp ortant;width:13 0px">Exam Schedule:</td>
    <td>
    <select name="ddlExamSc hedule" id="ddlExamSche dule" style="width:18 0px"" >
    <option value="">- Exam Schedule -</option>
    <%
    if (testCenter!=nu ll)
    {
    try {
    rs2 = stmt.executeQue ry("SELECT * FROM WBITE.examSched ule e where TestCenterName= '"+testCenter+" ';");
    while (rs2.next()) {
    %>
    <option name="ddlExamSc hedule" id="ddlExamSche dule" value="<%=rs.ge tString(5)%>"> <%=rs.getString (2)+" ("+ rs.getString(3) +"-"+rs.getString( 4)+")"%></option>
    <%}
    } catch (Exception e) {
    System.out.prin tln(e);
    }
    } %>
    </select>
    </td>
    </tr>
    <tr>
    <td style="text-align:right!imp ortant;width:15 0px">Username: </td>
    <td>
    <input type="text" name="txtUserNa me" id="reg_usernam e" value="" maxlength="100" style="width:18 0px">
    </td>
    </tr>
    <tr>
    <td style="text-align:right !important;">Pa ssword:</td>
    <td>
    <input type="password" name="txtPasswo rd" id="txtPassword " value="" maxlength="17" style="width:18 0px"></td>
    </tr>
    <tr>
    <td style="text-align:right !important;">Re-enter password: </td>
    <td width="227" >
    <input style="width:18 0px" type="password" name="txtPasswo rd2" id="txtPassword 2" maxlength="17" onKeyUp="match( this.value,txtP assword.value) " >
    </td>
    </tr>

    <tr id="rowPassword " style="display: none">
    <td> </td>
    <td><span id="password_ma tch_status"><im g src="../Images/ImageButtons/disapprove_ovr. gif" alt="Does Not Match" width="35" height="25"> Passwords Do Not Match</span></td>
    </tr>

    <tr>
    <td style="text-align:right !important;">Fi rst Name:</td>

    <td><input style="width:18 0px" name="txtFirstN ame" maxlength="15" value="" type="text" onFocus="docume nt.getElementBy Id("rowPassword ").style.displa y=''"></td>
    </tr>
    <tr>
    <td style="text-align:right !important;">La st Name:</td>
    <td><input type="text" name="txtContac tNum" id="txtContactN um" value="" maxlength="100" style="width:18 0px" > </td>
    </tr>
    <tr>
    <td style="text-align:right!imp ortant;width:13 0px">Contact Number:</td>
    <td>
    <input type="text" name="txtContac tNum" id="txtContactN um" value="" maxlength="100" style="width:18 0px" > </td>
    </tr>
    <tr>
    <td style="text-align:right!imp ortant;width:13 0px">Email Address:</td>
    <td>
    <input type="text" name="txtEmailA dd" id="txtEmailAdd " value="" maxlength="100" style="width:18 0px" > </td>
    </tr>


    <tr>
    <td style="text-align:right !important;">Ge nder:</td>
    <td valign="middle" >
    <input name="rdioGende r" type="radio" value="Male" checked>Male
    <input name="rdioGende r" type="radio" value="Female"> Female

    </td>
    </tr>

    <tr><td height="17"></td></tr>
    <tr>
    <td></td>
    <td colspan="2">

    <input type="submit" name="submit" value="Register Examinee">

    </td>
    </tr>
    </table> <!--END of Registration Form-->

    </form>


    </td>

    </tr>
    <!--HOLDS the LARGEST ROW contains both forms-->
    </table>
    </td>
    </tr>
    </table>

    <!--DIV: Boxcontent -->

    </td>

    </tr>
    <tr>
    <td height="5"></td>
    </tr>
    </table>

    </body>
    </html>[/HTML]
    Last edited by acoder; Aug 25 '08, 09:22 AM. Reason: Added [code] tags
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    [HTML]function populate(){

    ddlTestCenter = document.getEle mentById("regEx aminee");
    ddlTestCenter = "ddlExamSchedul e.do";
    ddlTestCenter.s ubmit();

    } [/HTML]

    please replace the code with

    [HTML]function populate(){

    ddlTestCenter = document.getEle mentById("regEx aminee");
    ddlTestCenter.a ction = "ddlExamSchedul e.do";
    ddlTestCenter.s ubmit();

    } [/HTML]

    this. Hope this will work. try it and post back ur result

    Regards
    Ramanan Kalirajan

    Comment

    • colyn7
      New Member
      • Aug 2008
      • 8

      #3
      thanks but it still didn't work..

      Do I still need a helper of some class.. cause i kinda receive an error that there is a missing file in cgi-bin...

      what could it be? am not using any tool in web app cause my pc is rather slow.. 512mb only, am using notepad++.. it would have been much easier if i'm using eclipse or netbeans cause it has some helper...

      please.. anyone.. I was able to see the page.. but when i'll select an option, it won't reload the page or submit it when onChange on select option...

      i hope someone will be able to help me on this...thanks..

      Comment

      • RamananKalirajan
        Contributor
        • Mar 2008
        • 608

        #4
        Originally posted by colyn7
        thanks but it still didn't work..

        Do I still need a helper of some class.. cause i kinda receive an error that there is a missing file in cgi-bin...

        what could it be? am not using any tool in web app cause my pc is rather slow.. 512mb only, am using notepad++.. it would have been much easier if i'm using eclipse or netbeans cause it has some helper...

        please.. anyone.. I was able to see the page.. but when i'll select an option, it won't reload the page or submit it when onChange on select option...

        i hope someone will be able to help me on this...thanks..
        Hi for that function u have never made a call. Please explain me ur requirement dont confuse with ur codes. Just post onchange of the select the control should transfer to which page. On which component you want to make submit. please explain that clearly. I will surely help u out.

        Regards
        Ramanan Kalirajan

        Comment

        • Ferris
          New Member
          • Oct 2007
          • 101

          #5
          try this:

          <select name="list" onChange="docum ent.getElements ByName['regExaminee'][0].submit();">

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            colyn7, welcome to Bytes! Please remember to follow the posting guidelines when posting in the forum. Code tags are important as are good thread titles. I've added the missing code tags and changed the thread title for you. Please use a good one in future. Thanks!

            Comment

            • colyn7
              New Member
              • Aug 2008
              • 8

              #7
              Originally posted by acoder
              colyn7, welcome to Bytes! Please remember to follow the posting guidelines when posting in the forum. Code tags are important as are good thread titles. I've added the missing code tags and changed the thread title for you. Please use a good one in future. Thanks!
              thanks a lot.. am still a newbie here.. Thanks...

              Comment

              • RamananKalirajan
                Contributor
                • Mar 2008
                • 608

                #8
                Originally posted by colyn7
                thanks a lot.. am still a newbie here.. Thanks...
                Wether u got ur code working

                Regards
                Ramanan Kalirajan

                Comment

                • colyn7
                  New Member
                  • Aug 2008
                  • 8

                  #9
                  hmm.. thank you very much for the suggestion..

                  regarding the functions.. those are the functions i've tried calling onChange at select options.. but it didn't seem to work out..

                  On our project, the second option is dependent on the first selection..

                  that's why I have to submit the first selection for the second selection to appear...

                  But I can't submit it so far.. the page should reload when submitted, right? It didn't..

                  I think something's wrong on my following codes... that has nothing to do with the onChange.. because I've tried replacing my codes with this..

                  Code:
                  <Form Name="try"> <input type="hidden" name="hiddenopt" value="secret"> <select name="list" onChange="document.forms['try'].submit();"> <option value="1">First option</option> <option value="2">Second option</option> <option value="3">Third option</option> </select></form>
                  it seems to work out.. so i think the problem is not on the function but on the codes somewhere.. all my options comes from our database.. that's why its so hard on me.. But, I also tried removing the JSP codes from it and replace the options this
                  Code:
                  <select name="list" onChange="document.forms['try'].submit();"> <option value="1">First option</option> <option value="2">Second option</option> <option value="3">Third option</option> </select>
                  even though I've replaced it (the select options only not the whole form), it didn't work out...

                  I mean.. When I replaced the whole form, it worked out.. but when i replaced the select options only, it didn't.. Both removing the JSP codes.. what could be the problem on my codes?

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Originally posted by colyn7
                    On our project, the second option is dependent on the first selection..

                    that's why I have to submit the first selection for the second selection to appear...
                    That's not strictly true because you could use Ajax or load all the options and call a JavaScript function to change the options onchange, but what you're trying should also work.

                    I notice in your first post that some of the hidden fields are outside the form. What you've posted in the last post didn't work because the form isn't named "try".

                    Comment

                    • colyn7
                      New Member
                      • Aug 2008
                      • 8

                      #11
                      thanks for the help.. the submit() seems to work but there seems to be an error still..

                      here is my code:
                      Code:
                      		 <form name="regExaminee" method="post" action="regExaminee.jsp" >   			   
                      <!--Start of Registration Form-->         
                      <% 			String testCenter = request.getParameter("ddlTestCenter"); 			
                      String driver = "com.mysql.jdbc.Driver";            
                       String url = "jdbc:mysql://192.168.0.9:3306/WBITE?user=root";          	Connection con = null;             
                      ResultSet rs = null; 			
                      ResultSet rs2 = null;             
                      Statement stmt = null; 			
                      con = DriverManager.getConnection(url); 			
                      stmt = con.createStatement(); 		           %> 		 
                      <tr>             
                      <td style="text-align:right!important;width:130px">Test Center:</td>   
                         	<td> 			
                      <input type="hidden" name="hiddenopt" value="secret"> 
                      <select name="ddlTestCenter" id="ddlTestCenter" style="width:180px" onChange="this.form.submit();">
                      <option value="">- Test Center -</option>
                      <% 		 			  try { 	                rs = stmt.executeQuery("CALL `WBITE`.`uspSelectTestCenter`()");
                      while (rs.next()) { 			 			%> 			
                      <option name="ddlTestCenterOption" id="ddlTestCenterOption" value="<%=rs.getString(1)%>" selected="selected"> <%=rs.getString(1)+" ("+ rs.getString(2) +")"%></option> 
                      
                      <% 		 			}             
                      } catch (Exception e) {                 
                      System.out.println(e);             }             %> 
                      </select>
                      </td>
                      </tr> 
                      <tr>
                      <td style="text-align:right!important;width:130px">Exam Schedule:
                      </td>
                      <td> 
                      <select name="ddlExamSchedule" id="ddlExamSchedule" style="width:180px"" >
                      <option value="">- Exam Schedule -</option>
                       <% 		if (testCenter!=null) 		{ 			  try { 	                rs2 = stmt.executeQuery("SELECT * FROM WBITE.examSchedule e where TestCenterName='"+testCenter+"';"); 	 
                       while (rs2.next()) { 			 %>
                      <option name="ddlExamSchedule" id="ddlExamSchedule" value="<%=rs.getString(5)%>"> <%=rs.getString(2)+" ("+ rs.getString(3)+"-"+rs.getString(4)+")"%></option> 
                       <%} 			
                      } catch (Exception e) { 
                                      System.out.println(e);             }          }   %> 			</select> 			
                      </td> 		
                      </tr> 	
                      </form>
                      and then its output is this...


                      and when i select an option, it becomes like this...


                      the layout is destroyed.. the another row seem to be in the same cell with the form...
                      why? what is wrong with my code.. i'll really appreciate any help...

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Can you post the client-side version of your code, i.e. as it appears in the browser.

                        Comment

                        • colyn7
                          New Member
                          • Aug 2008
                          • 8

                          #13
                          i was able to solve that problem ablready.. the problem lies on the second combo box.. what could be something wrong in it.. i think it has something to do with the conditional clause...

                          Comment

                          • colyn7
                            New Member
                            • Aug 2008
                            • 8

                            #14
                            i was able to retrieve the data from the 1st combo box.. thru Javascript, now my problem is how to pass that variable from Javascript to JSP...

                            like..
                            Code:
                            function getFirstData(theValue) 		
                            { 			
                              var firstComboValue = theValue; 
                              alert(firstComboValue); 		
                            }
                            how can i pass the variable firstComboValue to JSP codes?

                            Comment

                            • colyn7
                              New Member
                              • Aug 2008
                              • 8

                              #15
                              i've researched on this and found out its not possible... and here's a given tip from another forum..

                              Call your JSP that creates or executes the JavaScript script that puts a value into the JS Variable, something like this:

                              "page.jsp"

                              Code:
                              <script> ...  
                              var toJSPVar = doSomething(parameters);   document.location.href="pageAux.jsp?jspVAR=" + toJSPVar; ...
                              </script>
                              and then create the JSP execution code in auxiliar page
                              "pageAux.js p"

                              Code:
                              <%  
                              String jspVarFromJS = request.getParameter("jspVAR"); ... ... 
                              %>
                              where is that pageAux.jsp go? is it okay to call it from the same page?

                              and the jspVAR from
                              Code:
                              document.location.href="pageAux.jsp?jspVAR=" + toJSPVar;
                              ,

                              what does it mean?

                              Comment

                              Working...