What is the difference between newyork.php and washington.php?
Why not make one page which deals out all the information, and use plain HTML forms to send info to that one page?
Make a single file which contains your options.
settings.php
PHP Code:
<?php
//create a single array of options
$cats = array( 'Automobile', 'Apparel','Careers','Consumer goods','Education','Electronics','Food and Beverage','Furniture','General Business','Society');
$states = array('Alaska','New York','Washington','Right State' );
?>
The first page:
nav.php
PHP Code:
<?php
// first use of your arrays
include 'settings.php' ;
?>
<form name="navList" action="item.php" method="GET">
<p>Select your state</p>
<select name="state">
<option value="home"> </option>
<?php
foreach ( $states as $key=>$state )
echo '<option value="' . $state . '">' . $state . '</option>' . PHP_EOL ;
echo '</select>' . PHP_EOL;
?>
</select>
<p>Pick a category</p>
<select name="cat">
<?php
foreach ( $cats as $key=>$cat )
echo '<option value="' . $cat . '">' . $cat . '</option>' . PHP_EOL ;
echo '</select>' . PHP_EOL;
?>
<input type="submit" value="Go"><font size="2"> </font>
</form>
then your form handler:
item.php
PHP Code:
// 2nd use of your arrays
include 'settings.php' ;
// some debug
if( isset( $_GET ) {
var_dump( $_GET );
}
// using the states array as a white-list of permitted variable values.
if( isset( $_GET['state'] && in_array( $_GET['state'], $states ) ){
//The state sent was one of the permitted ones.
}
That is untested, but the var_dump on the form handler should show you how your variables are being sent across.
There are many variations of doing this, like generating the array of states from your database, for example, use the POST method instead of GET and avoid urlencodeing problems, but for the level of question you are asking this example should help you understand how you don't need to use JS to send values around.
I am not saying don't use JS, you could certainly use it to check that a state was picked.
Sorry for changing the variable names city/state/option etc, alter them to suit your needs of course.
Bookmarks