Two things. First you are not asking it to alert the value, you are asking it to alert the document:
Code:
if (y.document)
{
y = y.document; //last assignment to y is the document.
y.getElementsByTagName("input")[0].value; //this does nothing, it's like saying "John" to the interpreter, but nothing is assigned.
alert(y); //if the rest of the code is working, this alerts 'HTMLDocument" or similar, or there could be a type mismatch and no alert.
}
If you want to alert the value of the input as indicated, do:
Code:
if (y.document)
{
y = y.document;
y = y.getElementsByTagName("input")[0].value;
alert(y); //now this alerts "John"
}
Now it will work. That is unless the browser has any reason to think that these two pages are not of the same origin. When testing locally, for some browsers that means that they must both be in the same folder. There could be other problems with local testing. So it's best to test live. Once live, the only requirement is that both pages be on the same domain.
Bookmarks