[英]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. 我有这个html代码,我想将值从0更改为美国,从1更改为澳大利亚,从3更改为加拿大,我需要在mysqol数据库中将此值的名称命名。
thanks 谢谢
html 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 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: 您可以执行以下操作: <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';
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.