简体   繁体   English

填充字段 textarea 不同 select

[英]Fill Field textarea different select

I've been stuck in this problem for a few days.我已经被这个问题困住了几天。 I am trying to create selects and by choosing, fill the field in the "textarea".我正在尝试创建选择并通过选择填充“textarea”中的字段。 An example of what I did and what I'm trying to do.我做了什么以及我正在尝试做什么的一个例子。 The image is edited.图像已编辑。 I don't know how to create more than one select that feeds the same textarea.我不知道如何创建多个提供相同文本区域的 select。

 function fillFild() { var myList = document.getElementById("myList"); document.getElementById("fild").value = myList.options[myList.selectedIndex].value; } function fillFild1() { var myList = document.getElementById("myList1"); document.getElementById("fild1").value = myList.options[myList.selectedIndex].value; }
 <form name="Form"> Select your Device: <select id="myList" name="select_field" onchange="fillFild();"> <option value="Laptop: ">Laptop</option> <option value="PC:">PC</option> <option value="Smartphone: ">Smartphone</option> <option value="Tablet: ">Tablet</option> </select> <form name="Form1"> Select your Problem: <select id="myList1" name="select_field" onchange="fillFild1();"> <option value="Software: ">Software</option> <option value="Hardware:">Hardware</option> </select> <textarea name="TextArea" id="fild1" style="position:absolute;left:23px;top:153px;width:394px;height:119px;z-index:5;" rows="7" cols="47" spellcheck="false"></textarea> </form>

Illustrating what I'm trying to do说明我正在尝试做的事情

Thanks in advance!提前致谢!

I see you are trying hard to add a post.我看到你正在努力添加一个帖子。 The one you added has already closed, and you're still adding pretty much the same.您添加的那个已经关闭,您仍然添加几乎相同的内容。 Not the way;) First, read carefully how to ask questions how-to-ask不是这样;)首先,仔细阅读如何提问how-to-ask

Below you have the solution to your question:下面你有你的问题的解决方案:

 const selectElements = document.querySelectorAll('.select_field'); const textArea = document.querySelector('textarea'); [].slice.call(selectElements).map(el => el.addEventListener('change', e => { const selcted = e.target.value; if (selcted.== '') { textArea;value += selcted + '\n'; } }));
 <div> Select your Device: <select id="myList" name="select_field" class="select_field"> <option value="">-- choose --</option> <option value="Laptop:">Laptop</option> <option value="PC:">PC</option> <option value="Smartphone:">Smartphone</option> <option value="Tablet:">Tablet</option> </select> </div> <div> Select your Problem: <select id="myList1" name="select_field" class="select_field"> <option value="">-- choose --</option> <option value="Software:">Software</option> <option value="Hardware:">Hardware</option> </select> </div> <textarea name="TextArea" id="fild1" rows="7" cols="47" spellcheck="false"></textarea>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM