can i use a drop down list without a submit button

Hi i am using a dropdown list to run different queries. the user selects an option from the list and then hits a submit button. i was just wondering if i could get the dropdown list to work without having to use the submit button? is there an easy to edit my code to acheive this ?

this is the some of the code i am using

Browes Films: Action Comedy Drama Thiller New Releases ScFi

[php]
if( isset( $_POST[‘search’] ) ){

$dropdownValue = $_POST[‘category’];

switch( $dropdownValue ){

case “Action” : $query = “SELECT name,description,image FROM movies WHERE genre =‘Action’ ORDER BY id DESC LIMIT $start,$per_page”; break;
case “Comedy” : $query = “SELECT name,description,image FROM movies WHERE genre =‘Comedy’ ORDER BY id DESC LIMIT $start,$per_page”; break;
case “Drama” : $query = “SELECT name,description,image FROM movies WHERE genre =‘Drama’ ORDER BY id DESC LIMIT $start,$per_page”; break;
case “Thiller”: $query = “SELECT name,description,image FROM movies WHERE genre =‘Thiller’ ORDER BY id DESC LIMIT $start,$per_page”; break;
case “Added” : $query = “SELECT name,description,image FROM movies ORDER BY id DESC LIMIT $start,$per_page”; break;
case “ScFi” : $query = “SELECT name,description,image FROM movies WHERE genre =‘SC-FI’ ORDER BY id DESC LIMIT $start,$per_page”; break;
default : die( “You have entered something that isn’t an option in my dropdown” );

    }

    }
	
	
	
	$query_run = mysql_query($query);

[/php]

Sure, you can add onchange=categorychanged(); to the SELECT and then set up a Javascript FUNCTION to handle whatever you want it to.

The issue is that normally with PHP you POST a form to a second page which handles the data that was changed or entered in the FORM page. So, without a submit button, you are not “posting” your entries in the form to a PHP program. Some people try to use on-form PHP code and just post to yourself. But, this causes all kinds of problems due to PHP really being SERVER-SIDE only software. Not designed for CLIENT-SIDE. (It can work, but, I do not suggest it. Unless you are using Javascript to LOAD PHP pages into iFrames and then using the data. This works well because the PHP will run SERVER-SIDE and fill data to be accessed by Javascript routines.)

In Javascript, it is very easy to set up a function to use the drop-downs and read the data in it and do whatever you wish. Remember the PHP code you showed runs server-side and can not be run in the browser the way you have it listed. It is run on the server then, rendered to the browser. You should look at Javascript for this. Ask any questions and we can help. (I’m gone for a few hours…)

Thanks for reply, i will try the javascript way myself, but do you have a simple example i could go use or can you edit my code , i’m just not to sure how to go about it. whenever you have some spare time there’s no rush thanks

Sorry, I am leaving now for a few hours… Here is a link that might help.
Select the DEMONSTRATION to see how it works. It is not a drop-down, but does the same thing.
It allows a CHANGE and then makes something happen based on it. It gives a nice effect.
I have it working in a drop-down somewhere and can help tomorrow or late tonight.

Good luck… http://remysharp.com/2007/09/18/auto-populate-multiple-select-boxes/

great thanks for help, i’ll try tomorrow.

Got it working very simple actually i just added the javascript onchange function to the select tag. as follows

<center><form action="films5.php" method="POST">
<center>Browes Films: <select name="category"onchange='this.form.submit()' ></center>
<option selected="selected">Choose a Genre...</option>
<option value="Added">All</option>
<option value="Action">Action</option>
<option value="Comedy">Comedy</option>
<option value="Drama">Drama</option>
<option value="Thiller">Thiller</option>
<option value="ScFi">ScFi</option>
</select>
</form>
<form action="films3.php" method="POST">
<input type="text" name="search_name" size="10" />
<input type="Submit" value="Search" name="search" />
</form></center>

Then i changed the isset function to check the select tag, (name=“catergory”) as folllows

[php]

if( isset( $_POST[‘category’] ) ){

$dropdownValue = $_POST[‘category’];

switch( $dropdownValue ){

case “Action” : $query = “SELECT name,description,image FROM movies WHERE genre =‘Action’ ORDER BY id DESC LIMIT $start,$per_page”; break;
case “Comedy” : $query = “SELECT name,description,image FROM movies WHERE genre =‘Comedy’ ORDER BY id DESC LIMIT $start,$per_page”; break;
case “Drama” : $query = “SELECT name,description,image FROM movies WHERE genre =‘Drama’ ORDER BY id DESC LIMIT $start,$per_page”; break;
case “Thiller”: $query = “SELECT name,description,image FROM movies WHERE genre =‘Thiller’ ORDER BY id DESC LIMIT $start,$per_page”; break;
case “Added” : $query = “SELECT name,description,image FROM movies ORDER BY id DESC LIMIT $start,$per_page”; break;
case “ScFi” : $query = “SELECT name,description,image FROM movies WHERE genre =‘SC-FI’ ORDER BY id DESC LIMIT $start,$per_page”; break;
default : die( “You have entered something that isn’t an option in my dropdown” );

    }

    }

[/php]

Great! Always nice to complete a project…

Sponsor our Newsletter | Privacy Policy | Terms of Service