usmbay
asked on
pass drop down value to php
Hello,
I want to return the value from drop down list to use it in php script
<form name="test" method="post" action="--WEBBOT-SELF--">
<select size="1" name="period" onChange="getValue(this.fo rm)">
<option selected value="all">Select a year</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
</select>
</form>
<SCRIPT language=JavaScript>
function getValue(form) {
var val=form.period.options[fo rm.period. options.se lectedInde x].value;
}
</script>
<FORM name="form1" method="post" action="access.php?market= ca">
<SELECT name="supplier" onChange="document.getElem entById('f orm1').sub mit();">
<OPTION value=""></OPTION>
<?PHP echo $supplierCA;?>
</SELECT>
</FORM>>>
so the user select the year and then select a supplier from second dropdown list it goes to access.php
I want read the value of year in this access.php
Thanks
I want to return the value from drop down list to use it in php script
<form name="test" method="post" action="--WEBBOT-SELF--">
<select size="1" name="period" onChange="getValue(this.fo
<option selected value="all">Select a year</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
</select>
</form>
<SCRIPT language=JavaScript>
function getValue(form) {
var val=form.period.options[fo
}
</script>
<FORM name="form1" method="post" action="access.php?market=
<SELECT name="supplier" onChange="document.getElem
<OPTION value=""></OPTION>
<?PHP echo $supplierCA;?>
</SELECT>
</FORM>>>
so the user select the year and then select a supplier from second dropdown list it goes to access.php
I want read the value of year in this access.php
Thanks
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Do you mind having the data traveling to access.php in GET only?
If not, the its as simple as creating another JS function which collects data from all the forms and then sends it off to access.php.
Use this JS function and then change
<SELECT name="supplier" onChange="document.getElem entById('f orm1').sub mit();">
to
<SELECT name="supplier" onChange="sendValues();">
If not, the its as simple as creating another JS function which collects data from all the forms and then sends it off to access.php.
Use this JS function and then change
<SELECT name="supplier" onChange="document.getElem
to
<SELECT name="supplier" onChange="sendValues();">
function sendValues() {
// get forms
var yearform = document.getElementById('test');
var supplierform = document.getElementById('form1');
// get selected values from forms
var year = yearform.period.options[yearform.period.options.selectedIndex].value;
var supplier = supplierform.options[supplierform.supplier.options.selectedIndex].value;
// create full URL
var address = 'access.php?market=ca&year='+year+'&supplier='+supplier;
// go there
window.locaction=address;
}
ASKER
Thanks
<input type="hidden" name="period" value="<? print $_POST['period']; ?>" />
You would then access them in access.php using post variables.
$period = $_POST['period'];
$supplier = $_POST['supplier'];