Jump to content


Photo

can you do onChange for a jump menu in php?


  • Please log in to reply
5 replies to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 26 August 2006 - 07:47 AM

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://theeventorgan...om/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.
$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>';

Thanks
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 26 August 2006 - 08:09 AM

php runs on the server, so for any php code to run, your page would need to be re-requested.

#3 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 26 August 2006 - 08:18 AM

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
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#4 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 26 August 2006 - 09:00 AM

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.

$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>';
		

I know what to do, its just doing it.
I just need to place the one thats selected into a variable.


How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 26 August 2006 - 09:31 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 26 August 2006 - 09:47 AM

OK, cheers mate.
I'll go check it out.
How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users