Link to home
Start Free TrialLog in
Avatar of marc_rabil
marc_rabil

asked on

Onchange Causes Blank Frame in IE6

I am experiencing odd behavior with Internet Explorer 6 (exact version = 6.0.2900.2180.xpsp_sp2_rtm.040803-2158).
The basic problem is that a frame becomes blank when the following events occur:

1. The user submits a form that has a significant delay (>3 seconds)
2. On the same frame as the submitted form is a select (drop-down) with an onchange handler that also goes to the server
3. While waiting for the submit to return, the user clicks on the select so that its list is displayed (but does not actually click on an item)
4. When the submit returns (provided the drop-down list is still displayed), an onchage event is fired (even though the user never actually clicked on an item)
5. The onchage handler makes another request on the server, the server returns the correct page, but it is not displayed - the frame goes blank

Interestingly, this problem does not occur when the frame page is the top frame or with IE5.5 or Netscape. Here is some code to reproduce it:

The overall frameset (index.html):
======================
<html>

<frameset rows="120,*">
  <frame src="header1.html" name="header">
  <frame src="main.html" name="main">
</frameset>

</html>

The Main Page (main.html):
==================
<html>
<head>
<script>
function processOnchange() {
  window.location.href ="onchange.html";
}
</script>
</head>
<body>
<form name="form1" action="DelayServlet" method="post">
<select name="select1" onchange="processOnchange()">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html>

The Header Page (header1.html):
=====================
<html>
<body>
<h1>Header</h1>
</body>
</html>

The Onchange Page (onchange.html):
=======================
<html>
<body>
<h1>Onchange Page</h1>
</body>
</html>

DelayServlet (doesn't have to be a Servlet, just something that causes a delay and returns the same page):
====================================================================
public class DelayServlet extends HttpServlet {
 
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {
      Thread.currentThread().wait(3000);
    }
    catch(InterruptedException e) {
      e.printStackTrace();
    }
    RequestDispatcher rd = req.getRequestDispatcher("main.html");
    rd.forward(req, resp);
  }
}

Hopefully if I've cut and pasted everything correctly, the problem will be demonstrated by loading index.html and following the steps at the beginning of this question. Also as previously noted, if you just load main.html and follow the same steps there is no onchange event and no problem.

Marc
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you can try making the onchange conditional on whether the form is submitting:

var submitting = false;

function processOnchange() {
  if ( !submitting )
     window.location.href ="onchange.html";
}
</script>
</head>
<body onload="submitting=false;" >
<form name="form1" action="DelayServlet" method="post" onsubmit="return submitting=true;" >
<select name="select1" onchange="processOnchange()">
great minds think alike!
(and so do ours)
;-)
Avatar of marc_rabil
marc_rabil

ASKER

Thanks guys.  I forgot to mention that I already have figured out this solution.  Unfortunately, the real world application has many dynamically generated forms and scripts and ensuring this flag always gets set is going to be a fair amount of work.

If its the only way, I guess that's what I'll have to do, but I was hoping you experts would know what the underlying problem is.

Marc
Sorry, but I have not encountered such behaviour.
Also I cannot imagine that it works that way.
My understanding is that onchange tries to change the location even when the response is not back from last submit.
The fact the the new location request is not seen in Netscape or older IEs does only say that onchange did not fire correctly.

If you claim that onchange never has to be fired because the user did not select an option, then you are true (but looking is perhaps half selecting ;-)

I can tell you a story were we got ominous server crashes only from a testing location. All other location worked correctly with that page and server.
The differece was that those testing group used a slow ISDN router and has also the bad bahaviour to select the options by cursor keys (not by mouse)
So now in that server version was not a buffer overrun protection for long requests url.
So the onchange of the select with fifty options fired longer and longer action urls while they scrolled down the options list with the cursor!
After 2048 bytes the server buffer overflow occured.


Or was it 4096 bytes, I do not remember.
But the solution was to change the action concatination to parameter replacement until the server was upgraded.