Forum Moderators: open
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.
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.
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.