¿Extraer valor de la etiqueta de selección / opción en php?

I am not exactly how to do it and how to word the question, so i shall try my best (PS: i'm new to web dev, so please be clear in your answers if you could).

So, I have got a drop down menu with the list names, which are taken from my database. In that database i have a table with names column (the ones that are rendered to the dropdown box) and relevant information to those names. Now, I want that relevant information to appear below in a tag when a user choose one of those names. I also cannot use the form.submit() method because my submit button is already taken for something else.

Here is the code to that bit:

<form name="name_choice" method="post" action="index.php">
     <select name="names" onchange="form.some_method()">
      <option value="NULL" selected="selected">--Select name--</option>
            for ( $i = 0; $i < $numrows; $i++ ) { //for all the columns, iterate and print out                  
                        $id_names = mysql_result($result, $i);
            echo "<option value='".$id_names."'>".$id_names."</option>";

So the bit above works fine, but the "some_method()" is my problem, i don't know what to trigger to display the text in the div below the drop down box (code is below for it):

<div class="information"> <!--if the name is chosen ONLY!-->
    if($_POST['names'] == "NULL") {
         echo '<p>Please select an option from the select box.</p>'; //this bit is for testing
    else {
         echo '<p>You have selected: <strong>', $_POST['names'], '</strong>.</p>';
                 //and then how to echo the relevant information?:(
</div><!--end of possible info-->

preguntado el 08 de noviembre de 11 a las 17:11

Thank you very much in advance for your time and sorry for the bad wording, i tried my best to describe the problem. -

1 Respuestas

onchange is a JavaScript event. PHP can't do realtime processing of form data, as it sits on the server and the form is on the client. You can sort of do it by using AJAX and passing the form data as the user types, but that would be a lot more work than is needed. Take a look at JavaScript form validation posts to get yourself headed on the correct path.

contestado el 23 de mayo de 17 a las 15:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.