我想在我的网页中显示用户从下拉框中选择的站点。我有值的网站链接和相应的网站名称在数据库中。我试过下面的代码。
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','username','pass','db_name');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM Details WHERE ID = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<script>
function goToPage763(mySelect){
frames['iframe2'].location.src = $(mySelect).val();
}
</script>";
echo '<select id="size" onchange="goToPage763(this.value)">';
while($row = mysqli_fetch_array($result)) {
echo '<option value="'.$row['Website'].'">'.$row['Marketplace'].'</option>';
}
echo '</select>';//
echo "";
mysqli_close($con);
?>
受PHP影响的HTML代码
<select id="username" class="demo-default" placeholder="Select a seller" onchange="showUser(this.value)">
<option value="">Select a person...</option>
<option value="1">Butterflyfields</option>
</select>
<label for="seller">Marketplace: </label>
<select name="txtHint" id="txtHint" onchange="getSrc(this.value)" target="iframe2">
</select>
iframe的代码是
<iframe runat="server" id="iframe2" src="https://localhost/sim.php" height="680" width="100%" frameborder="1" allowTransparency="true">
<p>Your browser does not support iframes.</p>
</iframe>
我的问题是,我无法做到这一点,从数据库中显示帧中选定值的链接。
您可以使用JQuery实现这一点,如:
//put this after jquery.js
$('#txtHint').change(function() {
//set the iframe's src to the value from the selected option.
$('#iframe2').attr('src',$(this).val());
});