davey10101 Posted February 20, 2010 Share Posted February 20, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/192737-form-value-capture/ Share on other sites More sharing options...
vinpkl Posted February 21, 2010 Share Posted February 21, 2010 i think this is a php question. you have posted in wrong section vineet Quote Link to comment https://forums.phpfreaks.com/topic/192737-form-value-capture/#findComment-1015501 Share on other sites More sharing options...
khr2003 Posted February 21, 2010 Share Posted February 21, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/192737-form-value-capture/#findComment-1015527 Share on other sites More sharing options...
seventheyejosh Posted February 22, 2010 Share Posted February 22, 2010 $_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 Quote Link to comment https://forums.phpfreaks.com/topic/192737-form-value-capture/#findComment-1016268 Share on other sites More sharing options...
khr2003 Posted February 23, 2010 Share Posted February 23, 2010 my mistake. I concentrated on the php code and forgot the html part Quote Link to comment https://forums.phpfreaks.com/topic/192737-form-value-capture/#findComment-1016525 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.