更改选择选项值名称

时间:2015-10-09 18:16:18

标签: javascript html mysql

我有这个html代码,我希望将值从0更改为美国,从1更改为澳大利亚,从3更改为加拿大,我需要在mysqol数据库中为此值命名。

感谢

HTML

<form method="post" id="countriesForm" name="countriesForm" enctype="application/x-www-form-urlencoded">
<select id="select1" name="select1">
    <option value="0">USA</option>
    <option value="1">AUSTRALIA</option>
    <option value="2">CANADA</option>
</select>
</form>
<img id="flags" height="30" width="50" border="0" name="flags"></img>

JS

(function(){
var imageArray = new Array("http://www.agem.org/images/flags/united_states.png", "http://www.agem.org/images/flags/australia.png", "http://www.agem.org/images/flags/canada.png");
var altArray = new Array("USA", "AUSTRALIA", "CANADA");

    document.getElementById('select1').onchange = function() {
        var e = document.getElementById('select1');
        var index = e.options[e.selectedIndex].value;
        var targetImg = document.getElementById('flags');
        targetImg.src = imageArray[index];
        targetImg.alt = altArray[index];
    };
})();

1 个答案:

答案 0 :(得分:0)

您可以这样做:<option value="usa">USA</option>或者您可以在onSubmit-Listener中查看该号码是什么,然后更改应提交的值:

function submit() {
  var select1 = document.getElementById('select1');
  var index = select1.value;
  var country = 'usa';
  if(index == 0) {
    country = 'usa';
  } else if(index == 1) {
    country = 'australia';
  } else if(index == 2) {
    country = 'cananda';
  }
}