从下拉列表中加载带有链接的iframe

时间:2012-10-20 06:02:01

标签: php html iframe drop-down-menu

我有基础工作,我只需要正确的src从下拉列表中获取链接。代码到目前为止:

<form name="dropdownMenu" method="post">
<select name="Select1" style="width: 128px">
    <option value="pages/page1.php">Page1</option>
    <option value="pages/page2.php">Page2</option>
</select>
<input name="Button1" type="button" value="GO"
onclick='document.getElementById("content").
src="THIS IS WHAT I CANT MAKE WORK";'>

如果我将src更改为“pages / page1.php”,它会加载iframe,但似乎无法从下拉列表中加载它。

2 个答案:

答案 0 :(得分:0)

给你的SELECT一个id,然后引用SELECT

的值
<form name="dropdownMenu" method="post">
<select id="Select1" name="Select1" style="width: 128px">
    <option value="pages/page1.php">Page1</option>
    <option value="pages/page2.php">Page2</option>
</select>
<input name="Button1" type="button" value="GO"
onclick='document.getElementById("content").
src=document.getElementById("Select1").value;'>

答案 1 :(得分:0)

    <script type="text/javascript">
 function newSrc() {
  var e = document.getElementById("MySelectMenu");
  var newSrc = e.options[e.selectedIndex].value;
  document.getElementById("MyFrame").src=newSrc;
 }
</script>

<select id="MySelectMenu">
<option value="http://www.example.com">Website</option>
</select>

<button onClick="newSrc();">Load new source</button>