Jump to content

form value capture


davey10101

Recommended Posts

Hi,  I'm trying to capture the select value from this code into a php variable.  I use the onChange to call a function but want to capture this.value ($studentid) to use further down the page

 

<form>
Select a User:
<select name="users" onchange="showUser(this.value)">
   <option>Select student</option>
    <?php
    include("dbconnect.php"); 
    $query="select studentid, firstname, lastname from student order by firstname asc"; 
    $result=mysql_query($query); 
    while(list($studentid, $firstname, $lastname)=mysql_fetch_row($result)) 
    { 
     echo "<option value=\"".$studentid."\">".$firstname." ".$lastname."</option>"; 
    } 
    ?>    
</select> 
</form>  

 

I've tried the following...

 

echo "this.value";

echo $_POST["user"];

echo $studentid;

echo "<option value=\"".$studentid."\"></option>";

 

nothing seems to work  :(

Please help cheers! xx

Link to comment
https://forums.phpfreaks.com/topic/192737-form-value-capture/
Share on other sites

option tags should be included in <select name="NAME"></select> tags. In order to retrive the value of the option selected you can just use the name of the select as a reference.

 

like this:

echo $_POST['NAME'];

 

or any other that suites your application

Link to comment
https://forums.phpfreaks.com/topic/192737-form-value-capture/#findComment-1015527
Share on other sites

$_POST['user'] != $_POST['users']... ur select is name='users', you are requesting the user key, and yes this is a php question.

 

I'd say just do this in your processing page to make sure it is all there.

 


echo '<pre>';

print_r($_POST);

echo '</pre>';

exit;

 

and verify that your key is correct and populated.

 

and @khr2003, he is echoing the options with php inside of his <select> tags... they are there

Link to comment
https://forums.phpfreaks.com/topic/192737-form-value-capture/#findComment-1016268
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.