Hi guys,
This is a weird little problem.
I have a form which is doing a few different things.
Basically, it is a booking form and the user selects the number of bookings from a drop down menu. When they do this, I am dynamically creating a group of date form elements to correspond with the number they select.
So, selecting 2 bookings creates the following drop down date selectors in a div tag on my page:
day1 / month1 / year1
day2 / month2 / year2
Now, I need to make sure (in certain circumstances) that the dates selected here are in the past.
When I submit my form, I've managed to loop through each form element and the elements I've dynamically created above are alerted to me. Here's the code I used for that:
Now, the problem I'm having is that I need to get the selected value of each of the aformentioned elements but they come back as nothing, nada, zip!!!
To do this, I said:
Why are the values blank? Is it because the form elements are dynamic so somehow not 'really there' until the page is submitted? If it can find the form element, I can't see why it can't see its value.
I know I've done something silly here so please put me out of my misery!
Thanks in advance.
This is a weird little problem.
I have a form which is doing a few different things.
Basically, it is a booking form and the user selects the number of bookings from a drop down menu. When they do this, I am dynamically creating a group of date form elements to correspond with the number they select.
So, selecting 2 bookings creates the following drop down date selectors in a div tag on my page:
day1 / month1 / year1
day2 / month2 / year2
Now, I need to make sure (in certain circumstances) that the dates selected here are in the past.
When I submit my form, I've managed to loop through each form element and the elements I've dynamically created above are alerted to me. Here's the code I used for that:
Code:
for(j=0; j<document.forms[0].elements.length; j++){
alert(document.forms[0].elements.name);
}
Now, the problem I'm having is that I need to get the selected value of each of the aformentioned elements but they come back as nothing, nada, zip!!!
To do this, I said:
Code:
for(j=0; j<document.forms[0].elements.length; j++){
if(document.forms[0].elements[j].name=='p_day1') {
alert(document.forms[0].elements[j].value);
}
}
Why are the values blank? Is it because the form elements are dynamic so somehow not 'really there' until the page is submitted? If it can find the form element, I can't see why it can't see its value.
I know I've done something silly here so please put me out of my misery!
Thanks in advance.