我已经有了表单设置和所有内容。
<head>
<script language="javascript">
var i;
function fill_Cities(i){
var form1 = document.getElementById("form1a");
document.form1aa.Cities.options.length=0;
switch(i)
{
case 0:
form1.Cities.options[0] =new Option('calcutta','calcutta');
form1.Cities.options[1] =new Option('Delhi','Delhi');
form1.Cities.options[2] =new Option('Bombay','Bombay');
break;
case 1:
form1.Cities.options[0] =new Option('Alabama','Alabama');
form1.Cities.options[1] =new Option('Alaska','Alaska');
form1.Cities.options[2] =new Option('Arizona','Arizona');
form1.Cities.options[3] =new Option('Arkansas','Arkansas');
form1.Cities.options[4] =new Option('California','California');
form1.Cities.options[5] =new Option('Colorado','Colorado');
form1.Cities.options[6] =new Option('Connecticut','Connecticut');
form1.Cities.options[7] =new Option('Delaware','Delaware');
form1.Cities.options[8] =new Option('District of Columbia','District of Columbia');
form1.Cities.options[9] =new Option('Florida','Florida');
form1.Cities.options[10] =new Option('Georgia','Georgia');
form1.Cities.options[11] =new Option('Hawaii','Hawaii');
form1.Cities.options[12] =new Option('Idaho','Idaho');
form1.Cities.options[13] =new Option('Illinois','Illinois');
form1.Cities.options[14] =new Option('Indiana','Indiana');
form1.Cities.options[15] =new Option('Iowa','Iowa');
form1.Cities.options[16] =new Option('Kansas','Kansas');
form1.Cities.options[17] =new Option('Kentucky','Kentucky');
form1.Cities.options[18] =new Option('Louisiana','Louisiana');
form1.Cities.options[19] =new Option('Maine','Maine');
form1.Cities.options[20] =new Option('Maryland','Maryland');
form1.Cities.options[21] =new Option('Massachusetts','Massachusetts');
form1.Cities.options[22] =new Option('Michigan','Michigan');
form1.Cities.options[23] =new Option('Minnesota','Minnesota');
form1.Cities.options[24] =new Option('Mississippi','Mississippi');
form1.Cities.options[26] =new Option('Montana','Montana');
form1.Cities.options[27] =new Option('Nebraska','Nebraska');
form1.Cities.options[28] =new Option('Nevada','Nevada');
form1.Cities.options[29] =new Option('New Hampshire','New Hampshire');
form1.Cities.options[30] =new Option('New Jersey','New Jersey');
form1.Cities.options[31] =new Option('New Mexico','New Mexico');
form1.Cities.options[32] =new Option('New York','New York');
form1.Cities.options[33] =new Option('North Carolina','North Carolina');
form1.Cities.options[34] =new Option('North Dakota','North Dakota');
form1.Cities.options[35] =new Option('Ohio','Ohio');
form1.Cities.options[36] =new Option('Oklahoma','Oklahoma');
form1.Cities.options[37] =new Option('Oregon','Oregon');
form1.Cities.options[38] =new Option('Pennsylvania','Pennsylvania');
form1.Cities.options[39] =new Option('Rhode Island','Rhode Island');
form1.Cities.options[40] =new Option('South Carolina','South Carolina');
form1.Cities.options[41] =new Option('South Dakota','South Dakota');
form1.Cities.options[42] =new Option('Tennessee','Tennessee');
form1.Cities.options[43] =new Option('Texas','Texas');
form1.Cities.options[44] =new Option('Utah','Utah');
form1.Cities.options[45] =new Option('Vermont','Vermont');
form1.Cities.options[46] =new Option('Virginia','Virginia');
form1.Cities.options[47] =new Option('Washington','Washington');
form1.Cities.options[48] =new Option('West Virginia','West Virginia');
form1.Cities.options[49] =new Option('Wisconsin','Wisconsin');
form1.Cities.options[50] =new Option('Wyoming','Wyoming');
break;
case 2:
form1.Cities.options[0] =new Option('Essex','Essex');
form1.Cities.options[1] =new Option('London','London');
form1.Cities.options[2] =new Option('Perth','Perth');
}
}
</script>
</head>
<form name="form1aa" method="post" action="" id="form1a" >
<select name="country" onchange=" fill_Cities (document.form1aa.country.selectedIndex); ">
<option value="India">India</option>
<option value="U.S.A">U.S.A</option>
<option value="United Kingdom">United Kingdom</option>
</select>
<select name="Cities">
</select>
</form>
在用户选择要呈现某些文字的城市后,我想点击提交按钮。最好是在网页中而不是单独的对话框。
<input type="submit" />
我知道如何创建提交按钮但我不知道如何将其链接到城市表单并显示文本。
答案 0 :(得分:0)
将此添加到现有的JS代码中:
form1.addEventListener('submit', function () {
// Here you can add success message showing-code
// like: document.getElementById("div_with_message").style.display = 'block';
return false; // return false to prevent the browser from submitting. Assuming that is what you want.
});
答案 1 :(得分:0)
您可以使用以下内容来获取所选城市下拉列表的值,然后根据需要在您的应用程序/页面中使用此值:
var selectedValue = form1.Cities.options[form1.Cities.selectedIndex].value;
这可以在提交表单时完成。像这样:
注册您的提交功能:
form1.onsubmit=submitForm;
功能定义:
function submitForm()
{
var selectedValue = form1.Cities.options[form1.Cities.selectedIndex].value;
alert('value = ' + selectedValue); // for sample. change as you like
}