0

I have the following code below, that supposed to pass on value from one HTML page to another. The code works fine with Firefox, but it is not working for IE 11. Could you please tell me why the code is not working? Thanks in advance

FORM.HTML

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>OrderUp</title>
</head>

<body>
     <form method="get" action="results.html" >  
    Name : <input name = "name" type= "text" id="name">
    <br>
    <input value = "Submit" type = "submit" >
 </form>
</body>
</Html>

RESULTS.HTML

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Results</title>
</head>
<body>
    <h2> Your Form Has Been Submitted </h2>
<div class = "first"> Name: </div>
<script>
   let params = (new URL(document.location)).searchParams;
   let name = params.get("name");
   console.log(name) 
   document.querySelector('.first').innerText += name;
</script>
</body>
</html>
sam s
  • 83
  • 7

1 Answers1

0

The problem you have is that you're using features that aren't supported by IE11 (let, URL API). See my comments. The following works for me in IE11. It's based on this stackoverflow post. If instead you want to use ES6 syntax you can try an ES6 to ES5 transpiler.

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Results</title>
    <script>
var parseQueryString = function() {
    var str = window.location.search;
    var objURL = {};

    str.replace(
        new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
        function( $0, $1, $2, $3 ){
            objURL[ $1 ] = $3;
        }
    );
    return objURL;
};
    </script>
</head>
<body>
    <h2> Your Form Has Been Submitted </h2>
<div class = "first"> Name: </div>
<script>
   var params = parseQueryString();
   var name = params["name"];
   console.log(name) 
   document.querySelector('.first').innerText += name;
</script>
</body>
</html>
Jonathan Chaplin
  • 2,442
  • 1
  • 18
  • 21