Click to See Complete Forum and Search --> : Referencing things


Webskater
02-11-2003, 11:58 AM
Let's say I have two pages.
Page1 and Page2.
Page2 is opened by Page1.
Page1 has a text box on it called 'phone'.
<input type=text id=phone>
On Page1 I can refer to this textbox as:
phone.value = whatever
On Page2 I try to reference the textbox on page1 by saying:
opener.document.phone.value = whatever
I get an error message - "opener.document.phone is null or not an object".
If I put form tags around the text box:
<form name=ContactForm>
<input type=text name=phone>
</form>
I can refer to it successfully on Page2 as:
opener.document.ContactForm.phone.value = whatever.

My question is:
why can I refer to the text box phone on page1 when it is not on a form - but cannot reference it from page2?

khalidali63
02-11-2003, 12:12 PM
To me,I question seriously why one would put a form field without form tags?( but thats just me)
to me input fields and other form elements must be contained in the form and thats the right way to reference them

Khlid

Jona
02-11-2003, 12:14 PM
Ahh, the way JS works... actually I find it a good idea to always keep your form in there, whether or not it's needed on the page. Because I usually do not give the forms a name, either, unless it's a lengthy script., just like document.images[0]...