Question

I've been doing a chained select menu by Php, using a database SQL ( as i need later on t develop an update possibility for the client).

However, the chained menu ( at 2 levels) works perfectly,

Problem is I've no idea how to link the button to an other page once submitting . . . and depending of the "items" selected, If anybody can give me some highlite, i'll be really thanksfull.

Here is the Jquery part, which now display the value directly:, instead of this i 'd like to link to an other page.

$("#result").html('Your choice: '+result);

Here is the tutorial I've been following to do it:

http://www.yourinspirationweb.com/en/how-to-create-chained-select-with-php-and-jquery/

THank you so much !!

Was it helpful?

Solution

Firs, if you need to send the user to a different page depending on the selection, you should create a field "destination" where you can save the urls on the database:

CREATE TABLE `type` (
`id_type` int(4) unsigned NOT NULL auto_increment,
`id_cat` int(4) unsigned NOT NULL,
`name` varchar(40) NOT NULL,
`destination` varchar(40) NOT NULL,
PRIMARY KEY  (`id_type`)
) ENGINE=MyISAM AUTO_INCREMENT=15 ;

then get the urls from the table and put them on the option value

   public function ShowCategory()
    {
        $sql = "SELECT * FROM category";
        $res = mysql_query($sql,$this->conn);
        $category = '<option value="0">choose...</option>';
        while($row = mysql_fetch_array($res))
        {
            $category .= '<option value="' . $row['destination'] . '">' . $row['name'] . '</option>';
        }
        return $category;
    }

And finaly make a jQuery to redirect to the page on submit

$("#select_form").submit(function( event ) {
  var the_url = $("#type").val();
  window.location = the_url;
  event.preventDefault();
});

Hope that help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top