简体   繁体   中英

change de select option value name

I have this html code i want change the value from 0 to usa and from 1 to australia and from 3 to canada i need de name of this value in mysqol database.

thanks

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];
    };
})();

You can just do this: <option value="usa">USA</option> or you can check in your onSubmit-Listener what the number is and then change the value which should be submitted:

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';
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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