6

I have this HTML form

<form name="nextform" action="anotherpage.php" method="post" enctype="multipart/form-data">
    <input name="pinid" id="pinid" type="hidden">
    <input type="submit" name="submit" id="post" value="Lets Go" class="formButtonMap">
</form>

pinid dynamically gets a value using JavaScript. When it gets a value I alert it and it works.

But, when I click the Lets Go button, nothing happens. I see the Internet Explorer loading for a couple of minutes and then I get the message “The webpage does not respond”. If I hit refresh it goes to anotherpage.php but the values from the form did not arrive to the server.

Rarely shows this message:

Visual Studio Just-In-Time Debugger

An unhandled win32 exception occured in iexplorer.exe [688]

Possible Debuggers :

New Instance of Microsoft Visual Studio 2012

This behavior is observed only in Internet Explorer 11.0.2. The form works in older versions of Internet Explorer and also in Chrome and Firefox. I get no errors in IE’s console.

Here is the JavaScript code, placed above the form:

// called when another button is clicked - basicaly is websockets
function save() {
    var so = new WebSocket("ws://localhost:8000");
    so.onerror = function (evt) {
        alert('problem');
    }

    if (sara == 'LINES') {
        so.onopen = function() {
            so.send(JSON.stringify({
                command: 'insertAll',
                name: document.getElementById('name').value
            }));
        }
    }

    if (sara == 'POLY') {
        so.onopen = function() {
            so.send(JSON.stringify({
                command: 'insertHalf',
                name: document.getElementById('name').value
            }));
        }
    }

    so.onmessage = function (evt) {
        var received_msg = evt.data;

        document.getElementById("next").style.display = "block";
        document.getElementById("name").value = "";
        document.getElementById("descr").value = "";
        clearLinks();

        document.getElementById("pinid").value = received_msg;
        alert(document.getElementById("pinid").value); // works

        so.close();
    }
}

I tried to edit the code using document.getElementById("nextform").submit();, problem is still there.

Is it me? Is it a bug? What am I missing?

Palec
  • 12,743
  • 8
  • 69
  • 138
slevin
  • 4,166
  • 20
  • 69
  • 129
  • why do you need a value in the submit input? – w3jimmy Dec 26 '13 at 02:17
  • @w3jimmy That's the "name" of the text that the users sees. It could be "Download" or "Go back". You suggest I should delete it? – slevin Dec 26 '13 at 14:20
  • Your page actually posts if you see that, so problem doesnt seem like to be the button itself. Could something be wrong with the redirected page? – Kuzgun Dec 30 '13 at 15:52
  • Since you aren't uploading a file, maybe try it without the enctype="multipart/form-data"? – adam0101 Dec 30 '13 at 17:59
  • 1
    By the description, most likely the problem is on `anotherpage.php`, post your form to another (preferably empty) page and see if it does the same. Also posting the code of `anotherpage.php` would help. – Rafael Dec 30 '13 at 19:42
  • Can you change id="post" to something else than "post"? – Grzegorz Dec 30 '13 at 21:29

6 Answers6

4

Maybe not your issue, but:

<input type="submit" name="submit" ... >

Giving a form control a name of submit will replace the form's submit method with a reference to the control, so calling form.submit() will attempt to "call" the input.

RobG
  • 142,382
  • 31
  • 172
  • 209
  • Nice piece of advice, but nothing changed. Problem is still there – slevin Dec 21 '13 at 21:58
  • As I said, "maybe not your problem", it's just advice. – RobG Dec 22 '13 at 21:03
  • I know, and thanks for your time again. I have tried everything. Change the structure of JS, use `GET` instead of `POST`. Drives me crazy, cannot solve it. Maybe any other advise? Anything will do. I cannot make it work. – slevin Dec 22 '13 at 21:06
4

I believe this is a bug when setting form values to empty in IE.

I would suggest trying a different method to resetting the form values, I have used this method in the past:

document.getElementById('name').parentNode.innerHTML = '';
Andy
  • 4,538
  • 2
  • 26
  • 34
  • Can you provide a little context around this, and maybe your thoughts behind this approach? I looked at the workaround posted with the bug report but cannot implement because I'm not using jQuery. IE11 is crashing when entering data in a form for me -- I assumed it had something to do with auto-suggest, but can't debug to that end. – J.D. Pace Dec 30 '13 at 17:17
  • @Andrew Yes, has to do with that bug you mention. I tried the workaround there, and worked for me. My original code has a form with more than 5 fields. When submitted calls the `save()`. That function also clears the fields using JS. The bug in that form crashes the `nextform` form and also the browser. I APOLOGISE for not posting all my code, I did not know it had to do with the first form. I did NOT asked the same question twice. Because I thought the same code had two different problems. Turns out , its the same problem. I asked this one first.Thanks anyway – slevin Dec 31 '13 at 12:15
  • No worries @slevin, it just confused me as it appeared as though you were asking the same question. I'm glad the workaround has helped you. – Andy Jan 03 '14 at 10:26
3

hi might be problem in your code you miss to add id in form and you try to access form by it's id that you not define.

document.getElementById("nextform").submit();

its required

<form name="nextform" id="nextform" action="anotherpage.php" method="post" enctype="multipart/form-data">

...
...
...

</form>
jayesh
  • 2,422
  • 7
  • 44
  • 78
0

Trace through what happens in the anotherpage.php page when it receives the postback, evt.data might not be encoded as you expect (is it binary or text, if text, is it utf-8).

Postback to a different page where all it does is output the posted back values.

Does the socket close throw an exception?

 so.close();
Ben Adams
  • 3,281
  • 23
  • 26
0

My original code has a form with more than 5 fields. When submitted calls the save(). save() function also clears the fields using JS.

There is a bug in IE11, that crashes the browser if you try to clear more than 5 fields , using JS. See here , there is workaround.

That bug crashes the first form, then the nextform form and also the browser. I APOLOGISE for not posting all my code, I did not know it had to do with the first form.

Because I thought the same piece of code had two different problems , I posted another question, very similar , here

Community
  • 1
  • 1
slevin
  • 4,166
  • 20
  • 69
  • 129
0

In my case the input button had the same ID and NAME. So you can check if they are the same and if indeed they are the same use different value for one of the parameters.

I hope it helps.

Luchezar
  • 164
  • 1
  • 13