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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.