Javascript 如何从下拉列表中填写输入字段
所以这让我抓狂,我在寻找一个解决方案,它能从下拉列表中选择什么来填充输入字段 我当前的工作解决方案不包括下拉列表,如下所示:Javascript 如何从下拉列表中填写输入字段,javascript,jquery,html,Javascript,Jquery,Html,所以这让我抓狂,我在寻找一个解决方案,它能从下拉列表中选择什么来填充输入字段 我当前的工作解决方案不包括下拉列表,如下所示: <form method="link" action="dualstream/index.html"> <input value = 'apolloz' name="stream1" placeholder="" required="required" autofocus="autofocus" /> <input type="su
<form method="link" action="dualstream/index.html">
<input value = 'apolloz' name="stream1" placeholder="" required="required"
autofocus="autofocus" />
<input type="submit" class="button" value="Click to watch the stream" />
</form>
这样,auto会用apolloz填充文本字段,然后当您按submit时,它会将您带到使用apolloz一词的相关页面
我正在寻找一个解决方案,您可以从下拉列表中选择拖缆,选择它,该选项将填充文本字段,然后您可以提交
我确信这是基于javascript的,因为我见过类似的东西,它们使用数值
抱歉,如果这是一个有点模糊,但任何和所有的帮助是非常感谢 这很简单,如果您使用jquery,就可以做到这一点
$(function(){
$("#your_select").change(function(){
$("#your_input").val($('#your_select option:selected').val())
});
});
这很简单,如果使用jquery,就可以做到这一点
$(function(){
$("#your_select").change(function(){
$("#your_input").val($('#your_select option:selected').val())
});
});
假设您有一个selectbox selectid
假设您有一个selectbox selectid
试试这个
<form method="link" action="dualstream/index.html">
<input value = 'apolloz' id="txt" name="stream1" placeholder="" required="required"
autofocus="autofocus" />
<select id="mySelect" onchange="selectionchange();">
<option value="abc" >abc</option>
<option value="xyz" >xyz</option>
</select>
<input type="submit" class="button" value="Click to watch the stream" />
</form>
试试这个
<form method="link" action="dualstream/index.html">
<input value = 'apolloz' id="txt" name="stream1" placeholder="" required="required"
autofocus="autofocus" />
<select id="mySelect" onchange="selectionchange();">
<option value="abc" >abc</option>
<option value="xyz" >xyz</option>
</select>
<input type="submit" class="button" value="Click to watch the stream" />
</form>
你也可以使用javascript来实现这一点 在select的onchange函数上,u可以调用一个函数,将所选值放入输入中 像
你也可以使用javascript来实现这一点 在select的onchange函数上,u可以调用一个函数,将所选值放入输入中 像
如果该值仍在“选择”字段中,为什么需要将其复制到stream1字段中?只需将select放在表单中,并将其命名为stream1。如果该值仍在select中,为什么需要将其复制到stream1字段?只需将select放在表单中,并将其命名为stream1.raza/kingkero,这是spot on works,与我希望的方式非常接近,必须更改表单中的id,以便第一个框在选择时不会更改,但我刚刚意识到我希望这样做,感谢所有建议。raza/kingkero,这就是spot on的工作方式,几乎完全符合我的要求,必须对表单中的id进行更改,以便第一个框在选择时不会发生更改,但我刚刚意识到我希望如此,感谢所有建议。
<select id="element1" onchange="pickvalue()"/>
<option>asad </option>
<option>asad2 </option>
</select>
function pickvalue()
{
document.getElementById('yourinputid').value = document.getElementById('element1').value
}