-1

I'm having an issue with my codes concerning the transfer of information from one page to another using the url as shown below:

window.location.href ="form.html?uname="+uname;

The value is displaying in the url box but when I try to display it on the form.html page using the following code:

window.onload = function ()
{
    var name = document.getElementById("uname");
    alert(name);
}

The alert keep displaying null.

What is the issue because after an hour of troubleshooting, I can't seem to figure it out.

Is the null being displayed in the alert box means that the value is not being retrieve from the url?

Thanks in advance.

Rot-man
  • 18,045
  • 12
  • 118
  • 124
  • 1
    The query string of the URL of the current page is **not an element** – Quentin Mar 17 '19 at 11:05
  • 1
    Your alert displaying null has nothing to do with passing data between pages. It means you have no element with ID 'uname' at the time the script executes. – Mitya Mar 17 '19 at 11:06

1 Answers1

-1

document.getElementById('uname')

looks for an HTML element with the corresponding id. What you probably want to do is:

alert(uname)
Andre Nuechter
  • 2,141
  • 11
  • 19