spires Posted August 26, 2006 Share Posted August 26, 2006 Hi i am trying to build a jump dropdown menu. So every time they select an option from the menu, the selection will be stored into a variable e.g $cat = $_POST['cat']; http://theeventorganiser.com/register.phpExample.if you select: Lasers = $cat = 'lasers'; crew = $cat = 'crew';Here is the code i'm using. that dont work. Can someone please point me in the right direction.[code]$query = "SELECT * FROM category order by id DESC";$result = mysql_query($query) or die ("query 1 failed");$count = mysql_num_rows($result); $cat1 = '<select name="cat" onchange="reload(this.form)"> <option value="NULL" selected>- - - - - - - </option>'; while ($row = mysql_fetch_array($result)) { $category = $row['cat']; $cat1 .= '<option value="'.$category.'">'.$category.'</option>'; } $cat1 .= '</select>';[/code]Thanks Link to comment https://forums.phpfreaks.com/topic/18699-can-you-do-onchange-for-a-jump-menu-in-php/ Share on other sites More sharing options...
trq Posted August 26, 2006 Share Posted August 26, 2006 php runs on the server, so for any php code to run, your page would need to be re-requested. Link to comment https://forums.phpfreaks.com/topic/18699-can-you-do-onchange-for-a-jump-menu-in-php/#findComment-80624 Share on other sites More sharing options...
spires Posted August 26, 2006 Author Share Posted August 26, 2006 Thanks for your reply. Do you have any ideas of how this could be done. So far i have a database, with a table called categories, id, catsuball i'm trying to do. if the first dropdown menu is selected, then show all the 'sub' where cat is equal to the cat in the first dropdown. But i cant get the first dropdown to post the value.Any more help please. I can only do this in JAVA Script, but you have to enter in all of the values first. I need to be able to call them from a database.I hope this all makes sence Link to comment https://forums.phpfreaks.com/topic/18699-can-you-do-onchange-for-a-jump-menu-in-php/#findComment-80629 Share on other sites More sharing options...
spires Posted August 26, 2006 Author Share Posted August 26, 2006 OK.I've now stuck it into a from of its own to try out. but, it not passing the variable $category through the HTTPif i can do that, then i can GET the variable when it comes back.[code]$query = "SELECT * FROM category order by id DESC";$result = mysql_query($query) or die ("query 1 failed");$count = mysql_num_rows($result); $cat1 = ' <form name="url" method="post" action="'.$_SERVER['PHP_SELF'].'?cat='.$category.'"> <select name="cat" onchange="this.form.submit()"> <option value="NULL" selected>- - - - - - - </option>'; while ($row = mysql_fetch_array($result)) { $category = $row['cat']; $cat1 .= '<option value="'.$category.'">'.$category.'</option>'; } $cat1 .= '</select></form>'; [/code]I know what to do, its just doing it. I just need to place the one thats selected into a variable. Link to comment https://forums.phpfreaks.com/topic/18699-can-you-do-onchange-for-a-jump-menu-in-php/#findComment-80639 Share on other sites More sharing options...
.josh Posted August 26, 2006 Share Posted August 26, 2006 you can intermingle js and php with ajax. ajax is a js method of sending a request to the server (read: running a php script, for instance) and getting a response, without reloading your entire webpage. You can use ajax in combination with regular js to for instance, change the contents of dropdown box #2, based on a query to a db, by selecting something from dropdown box #1, before clicking some submit button. check out our sister site ajaxfreaks.com. hope this points you in the right direction. Link to comment https://forums.phpfreaks.com/topic/18699-can-you-do-onchange-for-a-jump-menu-in-php/#findComment-80648 Share on other sites More sharing options...
spires Posted August 26, 2006 Author Share Posted August 26, 2006 OK, cheers mate. I'll go check it out. Link to comment https://forums.phpfreaks.com/topic/18699-can-you-do-onchange-for-a-jump-menu-in-php/#findComment-80650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.