form.submit sometimes does not work!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Curious89
    New Member
    • Feb 2010
    • 4

    #1

    form.submit sometimes does not work!

    There are 3 buttons on a web page. On clicking each button a same popup window (say window1) opens up. Now there is another button on this popup window (window1), which further opens up to another popup window (say window2). On selecting some value from the 'window2', that value is passed onto the 'window1'. There is a 'Find' link on a 'window1', which calls a javascript function 'clicked()':

    Code:
        <head>
        <%
          Dim command
          command = Request.Form("hid");
          Response.Write(“Value” & command);  -- The value is not printed (Reason found after 
                                                       analysis that may be because the form is not submitted 
                                                        successfully)
        %>
    
        function clicked()
        {
           document.form.hid.value='FIND';
           alert("before");              -- This message box appears
          [B] document.form.submit();  [/B]-- after a lot of analysis the conclusion is that 
                                      this submit statement stops working (as on the status   
                                      bar 'Opening https:.....File1.asp?form=...' is not 
                                      displayed when 'after' message box appears
           alert("after");               -- This message box appears 
        }
    
        <body.......>
        <% if command = "FIND" then
           Response.Write ("Inside Find"); -- This message is not printed.
          // some functonality
    
        %>
        <form ....>
    
           <input type="hidden" name="hid" value="">
    
        </form>
        </body>
    This full code works fine on my machine. But this code does not work properly when run on the client-side!, although the same server and the same deployed application is being accessed. There is no particular sequence/scenario but for eg.
    When say button1 clicked->window1 opens->window2 is opened->value selected->returned to window1->Clicked on Find-> clicked on Ok->returned on the main page.
    Then repeated the same scenario for say 3rd button.
    (Till now 'Find' link works fine).
    Now repeated the same scenario for 2nd button and here 'after' message is obtained but 'inside Find' is not printed!!
    Last edited by Dormilich; Feb 20 '10, 12:50 PM. Reason: Please use [code] tags, when posting code
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hmmm ... i think i don't get it right ... could you rephrase that question so that it would be a bit more clear ... when is what and how passed between different windows? are those windows real popup windows?

    kind regards

    Comment

    • Curious89
      New Member
      • Feb 2010
      • 4

      #3
      What should happen: On clicking 'Find' link some records are retrieved from the database and displayed on the very same popup window. Now further on clicking 'Ok' the popup window closes and all the retrieved records are populated in a list box on the main page (where there were 3 buttons).

      What happens is: The above scenario does happen once or twice but the 3rd or the 4th time what happens is that on clicking 'Find', no records are retrieved and it goes to wait state. It sort of hangs. None of the links work any further, even the ones on the main page stop working. The window2 also doesn't open, blank page is displayed.

      In my first post, in the code, i have added the comments of exactly which all alerts/Response.Write are shown and which are not, when the problem occurs.

      Yes it seems the browser does not load, the page does not get refreshed. (When the 1st or the 2nd time 'Find' works fine, the page does get refreshed.)
      I can't hit anything on the current session anymore!

      After a lot of analysis, we have come to this conclusion that probably 'Find' link does not work after sometime because of some memory/buffer issue. I am using a 'for' loop which concatenates the strings retrieved on clicking 'Find' from the database.

      Code:
      var concatstr = "";
      for(i = 0 ; i < arr.length ; i++)
      {
           concatstr += arr[i]+";";
      }
      parent.opener.mainform.txtbx.value=concatstr; // transferring the semicolon separated string to the main form, where there are the 3 buttons
      (mainform - is the webpage where there are these 3 buttons.)
      (arr - is the array that stores all the retrieved strings from the database on clicking 'Find' link.)

      Probably a number of string objects are getting created and filling the buffer. What do u say?
      (On an average around 15 strings are retrieved each time)
      Probably which is why the 'request' is getting 'blocked'! It goes to wait state.

      No other link works as their URL don't work any further (the request is not going through, may be because of the previous pending request [Find link click]), only 'cancel' link works since it has only one statement written : "parent.clo se" (nothing to do with request,respons e).

      Is it so that the concatenation described above is creating 15! string objects (read as 15 factorial string objects) and thereby causing the block?

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        that small number of string-objects doesn't seem to be an issue that might cause such a problem ... but i cannot see some other obvious thing at the moment. might be to try that all in firefox and have a look at the firebug console might show more info ... i suspect a fatal javascript error that might block the submit then ... it could be a strange return-value that might break the concat-logic or similar ... for example some quotes or double qoutes in the response or something like that?

        kind regards

        Comment

        • Curious89
          New Member
          • Feb 2010
          • 4

          #5
          Originally posted by gits
          that small number of string-objects doesn't seem to be an issue that might cause such a problem ... but i cannot see some other obvious thing at the moment. might be to try that all in firefox and have a look at the firebug console might show more info ... i suspect a fatal javascript error that might block the submit then ... it could be a strange return-value that might break the concat-logic or similar ... for example some quotes or double qoutes in the response or something like that?

          kind regards
          I will definitely try this out, that you have suggested.

          Some more information about the code:
          We are opening and closing connection on each opening of the popup window. (opening-closing, opening-closing, opening-closing, .....).
          Can this be also an overhead?

          I am posting some code portions also for your reference :

          Code:
          // When Ok button is clicked and the popup window closes after concatenating the string names and ids retrieved. After closing the listbox appears on the main page with the string names retrieved.
          function clickedOk()
          {
             var input1="<select name='myselect' style='width:435;' id='"+btnname+"lboxId' multiple>";         
              
             var input2=new StringBuffer();     
             var concatenated_pooloid = new StringBuffer(); 
             var concatenated_poolnames = new StringBuffer();
           
             for(i=0;i<val.length;i++)
             { 
               input2=input2.append("<option value='"+ (i+1) +"'>"+ val[i] +"</option>");        
               concatenated_pooloid.append(val[i]+";"); 
               concatenated_poolnames.append(val1[i]+";");
             } 
          
              var btn = "clearbutton"+btnname;
              var listbox = btnname+"lboxId";
              var imagebtn = "myIMGOk"+btnname;
          
          parent.opener.document.getElementById(names_divID).innerHTML = "";                                     
          parent.opener.document.getElementById(names_divID).innerHTML = parent.opener.document.getElementById(names_divID).innerHTML + "&nbsp;&nbsp;<img id='myIMGOk"+btnname+"' style='color: blue; text-decoration: underline; cursor: pointer;font-family: verdana;font-size: 7pt' 
          src='/images/ok_arrow.gif' border='0' />" +"&nbsp;<a id='clearbutton"+btnname+"' href=java-script:clearListBox('"+btn+"','"+listbox+"','"+names_divID+"','"+const_IDs+"','"+const_NAMES+"','"+imagebtn+"')><u>Clear</u></a>";
              
          parent.opener.document[const_FORMNAME][const_IDs].value = concatenated_pooloid+";";     
          parent.opener.document[const_FORMNAME][const_NAMES].value = concatenated_poolnames+";"; 
          parent.opener.document.getElementById(names_divID).style.display = "inline";      
          
          parent.close();
          }
          
          function StringBuffer() {  
             this.buffer = [];  
           }  
          
           StringBuffer.prototype.append = function append(string) {  
             this.buffer.push(string);  
             return this;  
           };  
          
           StringBuffer.prototype.toString = function toString() {  
             return this.buffer.join("");  
           };  
          
           function validateAndSubmit() {            
                          document.resourcePickerForm.hidCommand.value =  "FIND";
                          document.resourcePickerForm.action =  "popupWnd.asp?............";   // ....... means parameters
                          document.resourcePickerForm.submit();
              }
          
          <script type="text/java-script">
          
              // Global Variable Declaration
              var countTextBox = 0;
              var tempcount = 0;
              var totalSelected = 0;
          
              var selectedArray = new Array();
              var selectedArray1 = new Array();
              var count=0;
              var val = new Array();
              var val1 = new Array();
          
              var const_FORMNAME='<%=(Request.QueryString("FormName"))%>';
              
           
          // This is called after checking the checkboxes displayed with retrieved strings and transferring them on the right-side of the page, the ones which we want to pass on the main page (displayed inside the listbox).
          function transfer()
          {         
             // Finding which checkboxes are checked and then adding them.
             var i=0;  
             while(document.getElementById("chkbox"+i))
             {   
              if(document.getElementById("chkbox"+i))
              {    
                 if (document.getElementById("chkbox"+i).checked)
                 {  
                          var inputTag = document.createElement ("input");
                          var type = "text";
                          inputTag.setAttribute("text",type);
                          inputTag.setAttribute("value",selectedArray[i]);             
                          inputTag.setAttribute("name",type+count);
                          inputTag.setAttribute("size",45);
                          inputTag.setAttribute("font-size",8);        
                          inputTag.setAttribute("id","strText"+count);
                          val[count]=selectedArray[i];   // Filling names  into array val                                 
                          val1[count]=selectedArray1[i]; // Filling ids  into array val1                    
          
                          document.getElementById('RightFrame').innerHTML  = document.getElementById('RightFrame').innerHTML + "<br  id='br"+count+"'>&nbsp;&nbsp;&nbsp;&nbsp;<input type='checkbox'  id='RFchkbox" + count + "' name='RFchkbox" + count + "'  visible='true' />&nbsp;<input type='text'  style='font-size:10;font-family:Verdana;' id='strText"+count+"'  value='"+selectedArray[i]+"' size='50' readonly='readonly'/>"    
          
                            count++;
                        }                                     
                  document.getElementById("chkbox"+i).checked="";
                  }            
               }
               i++;      
               document.getElementById("C1").checked="";            
             }
          }
          
          </script>
          
          
              <%
                  Dim command         
                  command = Request.Form("hidCommand")                
              %>
          
              <%
                Sub ChildDisplay(poolOID)
          
                Set LocalRS = Server.CreateObject("ADODB.RecordSet")
                strSQL="select name,id,..................."
          
                LocalRS.Open strSQL, Conn
          
                If Not LocalRS.EOF Then
          
                   LocalRS.MoveFirst 
                   j = 0 
              %>
              <%
                      Do While LocalRS.EOF <> True
              %>
              <tr>
                  <td width="2%" style="border:solid 1px  #6c9fc6;border-top:0;">
                      <font size="1" face="Verdana">
                          <input type="checkbox" id="chkbox<%= j %>"  name="C2" value="<% = LocalRS.Fields(0).value %>"  on-cl-ick='java-script:setSelected("<%=LocalRS.Fields(0).val ue %>", "<% = LocalRS.Fields(2).value %>","<%= j %>")'></font>
                          <input type="hidden" id="PoolId<%= j %>"  value="<% = LocalRS.Fields(2).value %>" />
                   </td>
                  <td width="50%" style="border:solid 1px  #6c9fc6;border-top:0;border-left:0;" >
                      <font face="Verdana" size="1">
                          <% = LocalRS.Fields(0).value %>
                      </font>
                  </td>  
               </tr>
              <%
              j = j + 1
                            LocalRS.MoveNext
                            If LocalRS.EOF = True then 
                                  exit do     
                            end if
                      loop
                %>
              <%
                end if
                LocalRS.Close     
                Set LocalRS=nothing                                   
          End Sub
              %>
          
          <body style="background-color: #fcfefd">
              <!-- #include virtual="/config/DataSource.asp"  -->
              <% if command = "FIND" then 
              %>
              <%
                Dim Conn          ' Connection Variable
                Dim RS             ' Result Set Variable
                Dim strSQL       ' SQL Query String
           
                Set Conn = Server.CreateObject("ADODB.Connection")
                Set RS = Server.CreateObject("ADODB.RecordSet")
          
                locName = Request.Form("location") 
                strSQL = "select name, id from table1 where location ='"+locName+"'"
          
                Conn.Open  SSdsn, SSdbuser, SSdbpass
          
                RS.Open strSQL, Conn    
          
                If Not RS.EOF Then
                      RS.MoveFirst
                End If                 
              %>
              <% end if %>
          
              <form name="popupWndForm" action="" method="post">
          
                  <input type="hidden" id="hidCommand" name="hidCommand"  value="" />
                  <a href="java-script:transfer()">Transfer</a>  
                  <a  href="java-script:validateAndSubmit()">Find</a>
                  <a href="java-script:clickedOk()">OK</a>  
          
                   <div class="leftframe">
                      <% if command = "FIND" then            
                      %>
          
                      <table id="table1" height="30" cellspacing="0">
                          <!-- MSTableType="nolayout" -->
                          <tr>
                              <td bgcolor="#c2d6e7" style="border:solid  1px #6c9fc6;">
                                  <input type="checkbox" name="C1"  value="yes" on-cl-ick="java-script:selectDeselectAll()"></td>
                              <td bgcolor="#c2d6e7" style="border:solid  1px #6c9fc6; border-left:0">
                                  <b><font face="Verdana" size="1">Name</font></b></td>                                       
                          </tr>
                          <%
                                ChildDisplay(RS.Fields(2))      
                          %>
                      </table>
          
                      <% end if %>
                    </div>  
             </form>
          
              <% if command = "FIND" then 
              %>
              <%
                RS.Close    
                Conn.Close        
                Set RS=nothing
                Set Conn=nothing
              %>
              <% end if %>
          
          </body>
          </html>
          Thanks in advance.

          Comment

          • Curious89
            New Member
            • Feb 2010
            • 4

            #6
            The problem is similar to one that is mentioned here:
            [URL=http://www.justskins.c om/forums/browser-hangs-when-posting-sometimes-85959.html]

            "If we close the IE window, and start open a new one, then things start loading again. And this is pretty much the only way to get to the web site after this happens, is to restart IE. Any attempts in the original IE window hang."

            Comment

            Working...