sfchun
02-20-2013, 10:11 AM
Hello
I wonder if there is a way to affect a value to a combobox which does not exists in predefined options ?
html part
<select name="EmailList" id="EmailListID">
<option value=""></option>
<option value="a@b.com">a@b.com</option>
<option value="c@d.com">c@d.com</option>
</select>
<textarea style="resize:none;overflow:hidden;display:none;" rows="1" cols="32" maxlength="128" name ="otherEmail" id="otherEmailID" value=""></textarea>
<input type="checkbox" name="EmailCheckBox" id="EmailCheckBoxID" onChange="checkEmailCheckBox();">
javascript part
function checkEmailCheckBox(){
var EmailListValue = document.getElementById('EmailListID').value;
var OtherEmailValue = document.getElementById('EmailListID').value;
if (document.getElementById('EmailCheckBoxID').checked){
document.getElementById('otherEmailID').value = EmailListValue; // <---- always works
document.getElementById('EmailListID').style.display = 'none';
document.getElementById('otherEmailID').style.display = 'block';
} else {
document.getElementById('EmailListID').value = OtherEmailValue; // <---- works only if the set value is present in combobox options ( here : a@b.com or c@d.com )
// if try to force another value it becomes 'empty value'...
document.getElementById('EmailListID').style.display = 'block';
document.getElementById('otherEmailID').style.display = 'none';
}
}
Thanks
I wonder if there is a way to affect a value to a combobox which does not exists in predefined options ?
html part
<select name="EmailList" id="EmailListID">
<option value=""></option>
<option value="a@b.com">a@b.com</option>
<option value="c@d.com">c@d.com</option>
</select>
<textarea style="resize:none;overflow:hidden;display:none;" rows="1" cols="32" maxlength="128" name ="otherEmail" id="otherEmailID" value=""></textarea>
<input type="checkbox" name="EmailCheckBox" id="EmailCheckBoxID" onChange="checkEmailCheckBox();">
javascript part
function checkEmailCheckBox(){
var EmailListValue = document.getElementById('EmailListID').value;
var OtherEmailValue = document.getElementById('EmailListID').value;
if (document.getElementById('EmailCheckBoxID').checked){
document.getElementById('otherEmailID').value = EmailListValue; // <---- always works
document.getElementById('EmailListID').style.display = 'none';
document.getElementById('otherEmailID').style.display = 'block';
} else {
document.getElementById('EmailListID').value = OtherEmailValue; // <---- works only if the set value is present in combobox options ( here : a@b.com or c@d.com )
// if try to force another value it becomes 'empty value'...
document.getElementById('EmailListID').style.display = 'block';
document.getElementById('otherEmailID').style.display = 'none';
}
}
Thanks