POST Variables Set by JavaScript Undefined [SOLVED]
Posted: Sun Oct 24, 2010 12:11 am
I have three text fields within an HTML form that may be populated in one of two ways:
1. The user may enter values in the three fields
2. The user may check a checkbox that sets default values for the three fields using JavaScript.
When the fields are set using the first method, things are fine. The form passes the values of the three fields using the POST method to the next page.
When the fields are set using JavaScript, the variables are not defined in the POST array. Instead, I get the following messages:
Notice: Undefined index: expMonth in C:\Apache\htdocs\PHP_functions.php on line 20
Notice: Undefined index: expDay in C:\Apache\htdocs\PHP_functions.php on line 21
Notice: Undefined index: expYear in C:\Apache\htdocs\PHP_functions.php on line 22
These messages occur in response to the following PHP code:
The JavaScript which sets the variables, in response to an ONCLICK event, seems to work fine on the same page. I don't see why fields set with JavaScript would not pass successfully through the POST array. The JavaScript that sets the fields looks like this:
I am using:
Firefox 3.6.11
Apache 2.2.14
PHP 5.2.12
Any help anyone can provide would be greatly appreciated!
1. The user may enter values in the three fields
2. The user may check a checkbox that sets default values for the three fields using JavaScript.
When the fields are set using the first method, things are fine. The form passes the values of the three fields using the POST method to the next page.
When the fields are set using JavaScript, the variables are not defined in the POST array. Instead, I get the following messages:
Notice: Undefined index: expMonth in C:\Apache\htdocs\PHP_functions.php on line 20
Notice: Undefined index: expDay in C:\Apache\htdocs\PHP_functions.php on line 21
Notice: Undefined index: expYear in C:\Apache\htdocs\PHP_functions.php on line 22
These messages occur in response to the following PHP code:
Code: Select all
$expMonth = $_POST['expMonth'];
$expDay = $_POST['expDay'];
$expYear = $_POST['expYear'];Code: Select all
var d = new Date();
d.setDate(d.getDate() + 90);
document.addRecord.expMonth.value = d.getMonth()+1;
document.addRecord.expDay.value = d.getDate();
document.addRecord.expYear.value = d.getFullYear();Firefox 3.6.11
Apache 2.2.14
PHP 5.2.12
Any help anyone can provide would be greatly appreciated!