Home > Article > Web Front-end > js method to accumulate selected values to the text box_javascript skills
The example in this article describes how to implement js to accumulate the selected value into the text box. Share it with everyone for your reference. The details are as follows:
JavaScript is implemented here to add the selected values of the list box or radio button to the text box. In some forms, we often see this function, which can save the user the trouble of input and improve the user experience. With some modifications, you can create more similar functions.
The screenshot of the running effect is as follows:
The specific code is as follows:
<html> <head> <title>js将选中值添加到文本框</title> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin oldvalue = ""; function passText(passedvalue) { if (passedvalue != "") { var totalvalue = passedvalue+"\n"+oldvalue; document.displayform.itemsbox.value = totalvalue; oldvalue = document.displayform.itemsbox.value; } } // End --> </script> </head> <body> <form name="selectform"> <select name="dropdownbox" size=1> <option value="">请选择</option> <option value="ASP">ASP</option> <option value="PHP">PHP</option> <option value="JAVA">JAVA</option> <option value="ASP.NET">ASP.NET</option> <option value="DELPHI">DELPHI</option> </select> <input type=button value="添加到列表中" onClick="passText(this.form.dropdownbox.options[this.form.dropdownbox.selectedIndex].value);"> </form> <form name="displayform" > <textarea cols="30" rows="5" name="itemsbox" ></textarea> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming design.