大家好,我需要两个选择下拉框的javascript编码,两者都是语言下拉 我需要条件的验证函数是
select
选项,html代码:
<select name="language1">
<option value='Select' selected="selected">Select </option>
<option value='Bengali'>Bengali </option>
<option value='Gujarati'>Gujarati </option>
<option value='Hindi'>Hindi </option>
</select>
<select name="language2">
<option value='Select' selected="selected">Select </option>
<option value='Bengali'>Bengali </option>
<option value='Gujarati'>Gujarati </option>
<option value='Hindi'>Hindi </option>
</select>
这个javascript是我添加的:
/* if regional language 2 filled without filling language1 then raise an error... */
if (document.f_edit_shop.language1.value) { }
else {
if (document.f_edit_shop.language2.value) {
document.getElementById("validationMessage").innerHTML=
" <font color='#FF0000'>Error: </font> You can not select Language 2
without selecting Language 1 !";
popup('validationPopup');
language2.focus();
return false;
}
}
我也需要这个脚本。 。
答案 0 :(得分:1)
var lng1 = document.f_edit_shop.language1;
var lng2 = document.f_edit_shop.language2;
var errBox = document.getElementById("validationMessage");
function validate() {
errBox.innerHTML = '';
if (lng1.selectedIndex !== 0 || lng2.selectedIndex !== 0)
errBox.innerHTML += 'Select an option for both boxes<br>';
if (lng1.selectedIndex === 0 && lng2.selectedIndex !== 0)
errBox.innerHTML += 'Select a language for first box<br>';
if (lng1.selectedIndex === lng2.selectedIndex)
errBox.innerHTML += 'You can\'t select same language twice<br>';
}