特定の値を持つオプションが選択フィールドに存在するかどうかを確認するにはどうすればよいですか?
<select>
<option value="o1">Option 1</option>
<option value="o2">Option 2</option>
</select>
select の値が "o1" = true の場合
select の値が "o4" = false の場合
特定の値を持つオプションが選択フィールドに存在するかどうかを確認するにはどうすればよいですか?
<select>
<option value="o1">Option 1</option>
<option value="o2">Option 2</option>
</select>
select の値が "o1" = true の場合
select の値が "o4" = false の場合
id
選択にフィールドを追加する場合は、次のようにしid="selector"
ます。
var x = document.getElementById("selector").options;
for(var i=0; i<x.length; i++){
if (x[i].value == "o1"){
...
等
オプションをループして、その値を確認できます。
var select = document.getElementById('selectID') ||
document.forms[formName or index].elements[selectName or index];
var options = select.options
for (var i=0, iLen=options.length; i<iLen; i++) {
if (options[i].value == 'foo') {
// found option with value 'foo'
}
}