我想获取所选的jquery值并打印为php变量。以下是用于显示jquery脚本
中的文本值的代码PHP代码
<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" /> ';
?>