<select id='vaccines'>
<?php
include realpath($_SERVER['DOCUMENT_ROOT'] . '/Classes/Controllers/DoctorController.php');
$names=DoctorController:: getVCName();
foreach ($names as $namesAvailable) {
echo "<option value='$namesAvailable[nameID]'>$namesAvailable[names]</option>";
}
?>
</select>
I want to take that value and store it in a php variable to send to a function in another page, is it possible?
It is possible in a number of ways;
You could create a form, send that form back to a PHP script and use $_POST
or some other method to fetch your data from the request.
You could also use Ajax and send the data to the PHP script via a change
event on the select
element (e.g. via JQuery
).
There are numerous other ways to do this, but if you read up on those two, you probably find that these are the easy ways to do this.
After you did that, you can ask questions about actually implementing this if something is not clear to you.
If the select is under a form tag, you will need to give it a name
in order to get its value on the next page, which the value got posted.
<form action="yourNextPage.php" method="post">
<select name='vaccines' id='vaccines'>
<?php
include realpath($_SERVER['DOCUMENT_ROOT'] . '/Classes/Controllers/DoctorController.php');
$names=DoctorController:: getVCName();
foreach ($names as $namesAvailable) {
echo "<option value='$namesAvailable[nameID]'>$namesAvailable[names]</option>";
}
?>
</select>
<input type="submit" name="sub" />
</form>
In yournextPage.php:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
$selectedvaccine = $_POST['vaccines'];
echo $selectedvaccine;
?>