|
|
Subject:
IE always reverts field data on javascript reload() calls
Category: Computers > Programming Asked by: doug8429-ga List Price: $10.00 |
Posted:
18 Aug 2005 08:50 PDT
Expires: 17 Sep 2005 08:50 PDT Question ID: 557260 |
I have a html form that has some text fields and some dynamically generated pulldowns. I use an "onChange" event for the first pulldown to query a database for the data for the second pulldown. After all the data is retrieved, I call javascript reload. This works just fine in Firefox, but in IE the reload() causes the text field data to revert to it's original values. I've tried calling reload with the "false" parameter, but it doesn't help. Here is some sample code that demonstrates the problem: <html><body> <table border=0 cellspacing=2> <tr> <td> <form class=form action=""> <input type=submit value="Undo Changes"> </form> </td> <td> <form class=form action=""> <input type=button value="Reload" onclick="location.reload();"> </form> </td> </table> <br> <form name="foo" method="post" action="foo.html"> Title:<br> <input type=text size="30" name="Title" value="Big Book"><br> Author:<br> <input type=text size="30" name="Title" value="Bill Smith"><br> </form> </body> </html> --- Try this code in both Firefox and IE, and you'll see the problem. |
|
There is no answer at this time. |
|
Subject:
Re: IE always reverts field data on javascript reload() calls
From: sifter-ga on 24 Aug 2005 19:11 PDT |
Hi, You need to post a bit more code so we can see what you are actually trying to achieve. The text values in the example above will always resolve to the values that are hardcoded in the value attribute, unless you send them back to the server and back to the client. Is the purpose of the reload to populate the values in your drop downs? If so you could consider sending them to the client on the first trip, save them in a javascript variable and populate them into the dropdowns on the client using javascript, thus saving a round trip to the server. I could show you how to do that. Of course this would be counterproductive if you have an awful lot of data (dropdown combinations) to send to client. Regards The Sifter. |
Subject:
Re: IE always reverts field data on javascript reload() calls
From: doug8429-ga on 26 Aug 2005 09:16 PDT |
Well, I resisted posting more code, because this is actually part of a much larger webapp, using Tomcat and a database connector called Velosurf. I have a Customer ID that get's passed in as an argument that is used to do a SQL query that populates a person contact pulldown list. I'm doing an onChange call on the Customer pulldown to recall the form with a new customer ID, that in turn repopulates the person contact list. Getting all of the customer and person contact info out of the database and into javascript variables will be really messy, and will complicate the app. I guess I'm just frustrated that Firefox can distinguish between a reload and a undo, where IE doesn't. I was hoping for a simpler javascript or even an activeX (which I know nothing about) fix to correct this problem. I'm not opposed to calling a conditional javascript function that does a reload() for Firefox and some other IE specific "update the pulldowns but leave the other fields alone" function. Another workaround I've tried is to save the customer ID choice with a submit form call, but then the undo function doesn't work. Thanks for your reply. Doug |
Subject:
Re: IE always reverts field data on javascript reload() calls
From: jeffemminger-ga on 04 Sep 2005 11:41 PDT |
here's one way to accomplish it, encoding the field values in the querystring and parsing them out upon reload. currently set up to only look for type="text" inputs. <html> <head> <title>test</title> <script type="text/javascript"> function doReload(form) { var vals = "", amp = ""; // get field values from form for (var x = 0; x < form.elements.length; x++) { var el = form.elements[x]; if (/text/i.test(el.type)) { vals += amp + el.name + "=" + encodeURIComponent(el.value); amp = "&"; } } // send to encoded url var url = location.pathname + "?" + vals; location.href = url; } function doOnload(form) { var url = location.href; var qs = url.split("?")[1]; // get field vals from querystring if (qs != null) { var pairs = qs.split("&"); // update the form fields for (var x = 0; x < pairs.length; x++) { var key = pairs[x].split("=")[0]; var val = pairs[x].split("=")[1]; form.elements[key].value = decodeURIComponent(val); } } } window.onload = function() { doOnload(document.getElementById("foo")); } </script> </head> <body> <table border=0 cellspacing=2> <tr> <td> <form class=form action=""> <input type=submit value="Undo Changes"> </form> </td> <td> <form class=form action=""> <input type=button value="Reload" onclick="doReload(document.getElementById('foo'));"> </form> </td> </table> <br> <form name="foo" id="foo" method="post" action="foo.html"> Title:<br> <input type=text size="30" name="Title" value="Big Book"><br> Author:<br> <input type=text size="30" name="Author" value="Bill Smith"><br> </form> </body> </html> |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |