Jump to content

can you do onChange for a jump menu in php?


spires

Recommended Posts

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.php

Example.
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
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,
cat
sub

all 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
OK.

I've now stuck it into a from of its own to try out.
but, it not passing the variable $category through the HTTP

if 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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.