meomike2000 Posted January 25, 2009 Share Posted January 25, 2009 What I am trying to do is create a sample, or test, form. I have created 2 sample forms with html/php as follows: <html> <head></head> <body> <?php //display form to choose state ?> <form method="POST" action="state.php"> Choose a state: <select name="state"> <option value="test1.1">test1.1</option> <option value="test1.2">test1.2</option> <option value="test1.3">test1.3</option> </select><br /> <br /> <input type="submit" name="submit" value="Select"> </form> </body> </html> This form gives me a way to make my first selection...... and the second: <html> <head> <title>state</title> </head> <body> <?php if (!$_POST['submitcity']) { //the form has been submitted //look for and process $state = $_POST['state']; //display state selected echo "$state <br />"; //select which list to display next ?> <form action="<?=$_SERVER['PHP_SELF']?>" method="post"> <?php switch ($state) { case 'test1.1': echo (' Select from test2: <select name="city"> <option value="test2.1.1">test2.1.1</option> <option value="test2.2.1">test2.2.1</option> <option value="test2.3.1">test2.3.1</option> </select><br /> <br /> <input type="hidden" name="state" value="test1.1" /> Select from test3: <select name="cat"> <option value="test3.1">test3.1</option> <option value="test3.2">test3.2</option> <option value="test3.3">test3.3</option> </select><br /> <br /> <input type="submit" name="submitcity" value="Select"> '); break; case 'test1.2': echo (' Select from test2: <select name="city"> <option value="test2.1.2">test2.1.2</option> <option value="test2.2.2">test2.2.2</option> <option value="test2.3.2">test2.3.2</option> </select><br /> <br /> <input type="hidden" name="state" value="test1.2" /> Select from test3: <select name="cat"> <option value="test3.1">test3.1</option> <option value="test3.2">test3.2</option> <option value="test3.3">test3.3</option> </select><br /> <br /> <input type="submit" name="submitcity" value="Select"> '); break; case 'test1.3': echo (' Select from test2: <select name="city"> <option value="test2.1.3">test2.1.3</option> <option value="test2.2.3">test2.2.3</option> <option value="test2.3.3">test2.3.3</option> </select><br /> <br /> <input type="hidden" name="state" value="test1.3" /> Select from test3: <select name="cat"> <option value="test3.1">test3.1</option> <option value="test3.2">test3.2</option> <option value="test3.3">test3.3</option> </select><br /> <br /> <input type="submit" name="submitcity" value="Select"> '); break; } } else { //if "submit" variable exist //the form has been submitted //look for and process $state = $_POST['state']; $city = $_POST['city']; $cat = $_POST['cat']; //display state selected before echo "$state <br />"; //display city selected echo "$city <br />"; //dislay the cat selected echo "$cat <br />"; } ?> </body> </html> this second form script uses your choice from the first form to determine which set of choices to let you choose from.... I would like to create a form that would let you choose a state from the first drop down menu, and that would determine the list of cities that would display in the second drop down list. hope somebody understands what I am trying to say and can help me or point me to a tutorial that can help me.... thanks mike.... Quote Link to comment Share on other sites More sharing options...
F1Fan Posted January 25, 2009 Share Posted January 25, 2009 You could do this two ways, and AJAX would be the best. But, if you don't know the first thing about AJAX, you'll need to learn. If you don't want to, the other option would be to pre-build a JavaScript library with all the cities in it. Then run a function that checked the state and builds the city list. Really, though, you should use AJAX. Here's a good tutorial to get you started: http://www.w3schools.com/ajax/default.asp Quote Link to comment Share on other sites More sharing options...
meomike2000 Posted January 25, 2009 Author Share Posted January 25, 2009 thank you for the link, i would prefer to learn..... been learning php/mysql, now trying to learn more about how to use javascript, and ajax would be another great tool to learn to use. thanks again mike..... Quote Link to comment Share on other sites More sharing options...
meomike2000 Posted January 28, 2009 Author Share Posted January 28, 2009 i have read the tutorial and one at tigzag.com that is very similar to the one at w3. but nether of them give much detail on how to do what i want to do. can somebody give me a link to a tutorial that would show more on how to do what i am trying to do. thanks mike...... Quote Link to comment Share on other sites More sharing options...
F1Fan Posted January 28, 2009 Share Posted January 28, 2009 http://www.dhtmlgoodies.com/index.html?whichScript=ajax_chained_select Quote Link to comment Share on other sites More sharing options...
meomike2000 Posted January 28, 2009 Author Share Posted January 28, 2009 thank you very much, that is will help me alot..... mike.... Quote Link to comment Share on other sites More sharing options...
meomike2000 Posted January 29, 2009 Author Share Posted January 29, 2009 i have copy and pasted the sample form, php script, and the ajax.js files, i followed the instructions, the form comes up but doesnt function. what could be wrong...... i am trying to learn how to use ajax but can not figure this out. here is the link: http://www.dhtmlgoodies.com/index.html?whichScript=ajax_chained_select i am running ubuntu 8.04, have apache2, and php5 on machine. that all works as my other scripts work...... please help...... mike....... Quote Link to comment Share on other sites More sharing options...
priti Posted January 29, 2009 Share Posted January 29, 2009 I think you start something like this For the chained dropdown problem following files will be created: 1. html - design your form 2. javascript -create your xmlhttprequest 3. php file which will accept country query the database and return the states. Now in which part you are getting stuck !! i think in javascript ?? Quote Link to comment Share on other sites More sharing options...
meomike2000 Posted January 29, 2009 Author Share Posted January 29, 2009 the problem was with the link to the js file. i fixed this link and now the sample is working and i can experiment with it to try to get it to do what i want. original: <script type="text/javascript" src="ajax.js"></script> after fix: <script type="text/javascript" src="js/ajax.js"></script> this was just a copy past from the link above and i thought that i followed the instructions exactly???!!!! not sure. thanks mike....... Quote Link to comment Share on other sites More sharing options...
F1Fan Posted January 29, 2009 Share Posted January 29, 2009 When working with AJAX and JavaScript, you should always watch your error console. It will give you great insight into your problem. Quote Link to comment Share on other sites More sharing options...
meomike2000 Posted January 31, 2009 Author Share Posted January 31, 2009 error console???????????? Quote Link to comment Share on other sites More sharing options...
F1Fan Posted January 31, 2009 Share Posted January 31, 2009 If you're using Firefox, go to Tools -> Error Console (or Ctrl+Shift+J). That will open your JavaScript error console. You'll probably see TONS of crap, so clear it. Then reload your page and run your stuff, all while watching the error console. If you don't understand the error, post the error here. If you don't see any errors, tell us and we'll go from there. I think IE and others have similar tools, but I am unfamiliar with them. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.