Forum Moderators: open

Message Too Old, No Replies

Updating form input text boxes

         

carneddau

12:57 pm on Mar 14, 2004 (gmt 0)

10+ Year Member



Hi,

My JavaScript knowledge is pretty basic and the solution to this is probably very simple, however I can't seem to find it!

I have an external calendar window that when a user clicks one of the dates it calls a function that posts the value back to the parent page to be displayed in a text box. Each time the function is called a counter is incremented so that the next call will drop the value into the next text box which are named date_1 date_2 date_3 etc etc.

My problem is that I can't seem to get the correct syntax for changing the text box name to drop the value into. I assumed that this would do it:

opener.document.my_form.date_ + counter + .value = day + '/' + month + '/' + year;

But this throws up the 'useful' IE Object Expected Error. I realise this is probably very simple but any help would be appreciated.

Birdman

1:13 pm on Mar 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It seems ok at first glance. I would try setting the creating the date variable on it's own line.

myDateObject = "date_" + counter;
myDateValue = day + '/' + month + '/' + year;

opener.document.my_form.myDateObject.value = myDateValue;

If you are still getting the error, try using alert to troubleshoot.

carneddau

1:37 pm on Mar 14, 2004 (gmt 0)

10+ Year Member



Hi,

Thanks for your quick response.

I just tried to create the text box name first before inserting it but it's still throwing errors back.

If I use this syntax:

myDateObject = "date_" + counter;
opener.document.my_form.myDateObject.value = day + '/' + month + '/' + year;

Using the Netscape JavaScript console it says opener.document.my_form.myDateObject has no properties

If I use this syntax:

myDateObject = "date_" + counter;
opener.document.my_form. + myDateObject + .value = day + '/' + month + '/' + year;

It says missing name after . operator on my_form

Any ideas where I'm going wrong here? When I hard code date_1 into the script it works fine but obviously doesn't achieve what I'm after.

carneddau

4:58 pm on Mar 14, 2004 (gmt 0)

10+ Year Member



Found a solution:

opener.document.getElementById("date_" + counter).value = day + '/' + month + '/' + year;