在文本字段中选择“选择显示”上的框值

select box value on select shows in the textfield

本文关键字:选择 选择显示 显示 文本 字段      更新时间:2023-09-26

我一直在尝试用 PHP 制作一个脚本,当我在选择框上选择任何选项时,当我选择它时,它的值会显示在文本字段中。请让我知道我该怎么做。我是一个菜鸟,所以如果它愚蠢,请接受我的问题。

请在以下i8ng链接上点击我的查询的图像帮助。

http://s18.postimage.org/d85l2m2nt/select_Box2.gif

如果您的元素位于表单中,则将以下侦听器放在 select 元素上:

onchange="this.form.textareaName.value = this.value"

其中 文本区域名称 是要设置其值的文本区域的名称。

<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
  $('#slectboxid option').click(function(){
      $('#textboxid').val($(this).val());
            });
});
</script>
</head>
<body>
<form action="#" method="post">
<select name="select" id="slectboxid">
  <option value="test">test</option>
  <option value="test2">test2</option>
</select>
<input type="text" name="text" id="textboxid" />
</form>
</body>
</html> 

使用jquery,上面的代码 snippet.it 会对你有所帮助。

请尝试这个

<html> 
<head>
<script type="text/javascript">
   function assignText(obj) {
    document.getElementById("textboxid").value = obj.options[obj.selectedIndex].value;
   }
</script>  
</head> 
<body> 
    <form action="#" method="post"> 
        <select name="select" id="slectboxid" onchange = 'assignText(this)'> 
            <option value="test">test</option>  
            <option value="test2">test2</option> 
        </select>
        <input type="text" name="text" id="textboxid" />
    </form> 
</body> 
</html>