I have a form that has 2 select boxes with multiple options.
For the First dropdown, I have assigned IDs to each option (1,2,3,etc)
For the Second dropdown, I have also assigned IDs to each option (01,02,03,etc)
When they choose an option from both select boxes and hit submit, I need to the form to processes the information so it realizes that both a First_id and a Second_id are selected, combines the two together -- $First_id.$Second_id -- and redirect the user to another page.
Hope that makes sense and someone can help me out.
Thanks!
now a follow up:
how do I set it up so that if they only choose one of the options, they are taken to the form page again and asked to choose one of the second options.
I'm assuming it would be something like:
IF id1 is empty then
or
IF id2 is empty then
$idselect(); // this calls function with variable name
Not sure how that is any easier? You will have to do the same checks, and processing. You also will not have a default setting like you will with the switch() function.
/* Default page - either the same page, or an error page */
$sPage='default.php';
/* Ensure both ids are set. It's okay if they are set but empty */
if (isset($_POST['id1']) && isset($_POST['id2']))
{
$aPageMap=array('101'=>'page1.php',
'102'=>'page2.php',
'103'=>'page3.php',
'201'=>'page4.php',
'202'=>'page5.php',
'203'=>'page6.php',
'301'=>'page7.php',
'302'=>'page8.php',
'303'=>'page9.php');
/* Create the array index - it's okay if it is not valid */
$iPageIndex=$_POST['id1'].$_POST['id2'];
/* Check to see if the array index is valid, if so, use it */
if (array_key_exists($iPageIndex,$aPageMap))
$sPage=$aPageMap[$iPageIndex];
}
/* Go to the page */
header('location: '.$sPage);
This could also be done in javascript, like so:
HTML Code:
<script type="text/javascript">
function go()
{
var o1=document.getElementById('id1');
var o2=document.getElementById('id2');
var i=0;l=o1.options.length;
for (i=0;i<l;i++)
if (o1.options[i].selected)
{
m=o2.options.length;
for (j=0;j<m;j++)
if (o2.options[j].selected)
location.href=o1.options[i].value+o2.options[j].value;
}
}
</script><!-- Be sure to give the <select> tags ids --><select name="id1" id="id1">
...
<select name="id2" id="id2">
...
<button onclick="go()">Go</button>