简体   繁体   中英

get value of select box without submitting a form

hi i want to get the value the user selected from the dropdown menu without submitting a form and save it in a php variable any ideas ??

<select name="car" value="Select" size="1">

<?php
$sql = "SELECT fullname FROM users"; 

    $result = mysql_query($sql) or die (mysql_error()); 

    while ($row = mysql_fetch_array($result))

    {
            $name=$row["fullname"]; 
            $options .= '<option value="'.$name.'">'.$name.'</option>';
    }

?>


<?php echo $options; ?>
</option>

</select>

I don't think you fully understand how PHP works server side, but to get the value of a dropdown menu without submitting it you'll need Javascript ( jQuery makes everything easier). From there you just send an AJAX request using JSON as data format and retrieve it from PHP with json_decode .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM