我想在我的网页中的iframe下拉列表中显示用户选择的网站。我有网站链接的值和数据库中相应的网站名称。我试过以下代码。
<?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>
我的问题是我无法做到这一点,在数据库的框架中显示所选值的链接。
答案 0 :(得分:-1)
您可以使用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());
});
希望这有帮助。