Email conversation
From | Matthew Hill |
To | Me |
Subject | Problem referencing an input field |
Date | 18 March 2004 12:59 |
Hi,
I have loaded a 'date picker' user control into a placeholder (which is in
turn in a table cell within a table within an absolute positioned <DIV>
element). Once the date is selected it trys to update the text input field
in the main window but reports it is 'undefined'. However when i look at
the source of my page it is there with the ID that i would expect. I seem
to be able to reference the label preceding the text box!
The javascript being used is
window.opener.StartDate_txtFromDate.value = '04/03/2004';
Is there any reason why i can't find this element?
Thanks for any help you can give.
Cheers
Matthew Hill
The relevant section of the web page source is:
<form>
<input name="StartDate:txtFromDate" id="StartDate_txtFromDate">
From | Me |
To | Matthew Hill |
Subject | Re: Problem referencing an input field |
Date | 17 March 2004 15:16 |
Matthew
your problem is that you are using invalid proprietary syntax to access the
contents of the box - the ID should not be a property of the window object
or opener object, it should be accessed using
document.getElementById
use the forms collection, and the name, not the ID - this way, it will be
fully cross browser as well.
window.opener.forms[0]['StartDate:txtFromDate'].value
hope this helps
Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
From | Matthew Hill |
To | Me |
Subject | Re: Problem referencing an input field |
Date | 18 March 2004 15:37 |
Mark
Thanks for the prompt reply, i am looking to put your suggestion into
operation but am curious if there is way it can be coded independant of the
form as i would like to be able to insert the user control in many
different pages where it may be in the second or third form on the page?
Ta
Matthew
From | Me |
To | Matthew Hill |
Subject | Re: Problem referencing an input field |
Date | 18 March 2004 15:56 |
give the form a name attribute (name="myform") and use:
...document.forms['myform'][etc...
this will reference the form by its name, not its index.
you can also use my generic referencing function:
http://www.howtocreate.co.uk/tutorials/javascript/elementcontents