多选入输入框 [英] Multiple selections into input box

查看:134
本文介绍了多选入输入框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些用户可以选择的国家。它们显示在下拉框中。目前我可以选择一个国家,它会将其填充到输入框中,但是我想知道是否有多种方法可供选择,并将它们放在同一个框中。



数据将从一个mysql数据库填充



希望即时消息让我自己清楚。



这是我的代码到目前为止:

JAVASCRIPT:

 < script language =JavaScripttype =text / javascript> 
<! -
function showSelected()
{
var selObj = document.getElementById('countries');
var txtTextObj = document.getElementById('txtText');

var selIndex = selObj.selectedIndex;
txtTextObj.value = selObj.options [selIndex] .text;
}
// - >
< / script>

HTML:

 <形式> 
< p>

< / form>< select id =countries>
< option value =val0>澳大利亚< / option>
< option value =val1> England< / option>
< option value =val2>法国< / option>
< option value =val3>意大利< / option>
< option value =val4>南非< / option>
< / select>
< input type =buttonvalue =Show Indexonclick =showSelected(); />
< / p>
< p>

< input type =textid =txtText/>

< br />
< / p>
< / form>

所以我想要的是如果您选择澳大利亚,它会在框中显示澳大利亚,然后返回到下拉菜单并选择南非,它将它放在与澳大利亚,南非相同的框中。



谢谢你们

解决方案

为什么不把新选择附加到已经在输入框中的文本。

  txtTextObj.value + = selObj.options [selIndex] .text +','; 


I have a selection of countries that a user can choose from. They are displayed in a dropdown box. At the moment I can select one country and it will populate it in the input box, however i want to know if there is a way of selecting more than one and it puts them in the same box.

The data will be populated from a mysql database

Hope im making my self clear.

Here is my code so far:

JAVASCRIPT:

<script language="JavaScript" type="text/javascript">
<!--
function showSelected()
{
  var selObj = document.getElementById('countries');
  var txtTextObj = document.getElementById('txtText');

  var selIndex = selObj.selectedIndex;
  txtTextObj.value = selObj.options[selIndex].text;
}
//-->
</script>

HTML:

<form>
  <p>

</form><select id="countries">
      <option value="val0">Australia</option>
      <option value="val1">England</option>
      <option value="val2">France</option>
      <option value="val3">Italy</option>
      <option value="val4">South Africa</option>
    </select>
    <input type="button" value="Show Index" onclick="showSelected();" />
  </p>
  <p>

    <input type="text" id="txtText" />

    <br />
  </p>
</form>

So what i would want is if you choose Australia, it shows Australia in the box, then go back to the dropdown and choose South Africa it puts it into the same box as: Australia, South Africa.

Thank you Guys

解决方案

why no just append new selections to the text already in the inputbox.

txtTextObj.value += selObj.options[selIndex].text +', ';

这篇关于多选入输入框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆