Get variable from drop down list

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
SerbanSpire
Posts: 19
Joined: Fri Dec 14, 2012 11:23 am

Get variable from drop down list

Post by SerbanSpire »

Ok, so I have this tiny little code here:

Code: Select all

<?php

include 'connect.php';

if(!isset($_SESSION)) { 
	session_start(); }

?>

<select name="title_select">
 
<?php

  $query = "SELECT DISTINCT char_title FROM titles";
  $result = mysql_query($query);
 while($row = mysql_fetch_assoc($result)){
			$title = $row['char_title'];			
			$title_options .= '<option>'.$title.'</option>';
			}

  $title_options .= '<option>'.$row.'</option>';

  echo "$title_options";
  
?>
 
 </select>
My problem: I want to store the user's selection from the drop down list WITHOUT a submit button. How would I do that?
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: Get variable from drop down list

Post by Chris »

Code: Select all

<select name="title_select" onchange="javascript: this.form.submit();">

Code: Select all

<?php
include 'connect.php';
if (!isset($_SESSION)) {
    session_start();
}
?>

<form action="the address to submit to" method="post">
    <select name="title_select" onchange="javascript: this.form.submit();">
        <?php
        $query = "SELECT DISTINCT char_title FROM titles";
        $result = mysql_query($query);
        while ($row = mysql_fetch_assoc($result)) {
            $title = $row['char_title'];
            $title_options .= '<option>' . $title . '</option>';
        }
        $title_options .= '<option>' . $row . '</option>';
        echo "$title_options";
        ?>
    </select>
</form>
Fighting for peace is declaring war on war. If you want peace be peaceful.
Post Reply

Return to “Beginner Help and Support”