I want to get the selected jquery value and print as a php variable. Here is the code for displaying the text value from jquery script
PHP Code
<script type="text/javascript">
$(document).ready( function ()
{
$('#selector').change(function()
{
var option = $(this).find('option:selected').val();
$('#showoption').val(option).show();
});
});
</script>
<?php
$config = array(
'DB_HOST' => 'localhost',
'DB_NAME' => 'roles',
'DB_USER' => 'root',
'DB_PASS' => ''
);
$db = new PDO('mysql:host=' . $config['DB_HOST'] . ';dbname=' . $config['DB_NAME'], $config['DB_USER'], $config['DB_PASS']);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo 'Select the role : <select id="selector">';
$sel_role = $db->query('SELECT * FROM role');
$sel_role->execute();
echo '<option selected="selected">Select a role</option>';
while ($row = $sel_role->fetch(PDO::FETCH_ASSOC))
{
$role_id = $row['role_id'];
$role_name = $row['role_name'];
echo '<option value='.$role_id.'>'.$role_name.'</option>';
}
echo '</select>';
echo '<input type="text" name="name" id="showoption" disabled="disabled" /> ';
?>