javascript - 在表单提交时清除<选项值>

标签 javascript html

作为 html 表单的一部分,我有一个选择框。

<select id="test" name="test">
<option value="text1">Text1</option>
<option value="text2">Text2</option>
</select>
<input type="text" id="my_text_box" name="my_text_box" class="hidden" />

使用 javascript,如何从表单通过电子邮件发送给我的结果中删除值“text2”?

编辑:

我需要保留 Text2。当用户选择此选项时,选择框将使用以下脚本更改为文本输入。我需要从结果文本输入中删除值“text2”。

 window.onload = function(){
 var dropDown = document.getElementById("test");
 dropDown.onchange = function() {
 var dropDownValue = this.value;
 if (dropDownValue == "text2") {
    dropDown.style.display = 'none';
    var textBox = document.getElementById("my_text_box");
    textBox.style.display = 'inline';
    textBox.value = 'Please enter something..';
  } else {
    dropDown.style.display = 'inline';
    textBox.style.display = 'none';
   };

   }

最佳答案

 document.getElementById('test').options[1].value = 'emailId';

关于javascript - 在表单提交时清除<选项值>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22802550/

相关文章:

javascript - 我可以将 HTML 代码写入 Window.showModalDialog() 吗?

javascript - NodeJS 中 unsigned short 的位移运算符

javascript - 奇怪的移动导航动画错误

javascript 未使用 setTimeout 执行,但使用按钮单击事件执行

javascript - jQuery 做一些事情取决于 url 路径

javascript - 如果我更改输入顺序,为什么控制台会给出不同的输出,如下所示

javascript - 在javascript中交换html表格元素(完整对象)

javascript - 动态创建选择字段 ->selected< 选项不显示

javascript - 如何获取被单击对象的副本

javascript - 是否可以在 AG-Grid 中过滤多个字符串?