"SAN CAZIANO" <al**********@tin.it> wrote in message
news:uh*******************@news3.tin.it...
check required in a select
how can i control if a combobox (a select) is not null (index is -1) or if
index is 0 if the first element is for example a null value or simply a
description of the field .
I try to use this
if (combobox.SelectedIndex==0 || combobox.SelectedIndex==-1)
{
alert('obbligatorio');
combobox.focus();
combobox.select();
}
Try this; watch for word-wrap.
<html>
<head>
<title>combobox.htm</title>
<script type="text/javascript">
function test() {
var combobox = document.form1.combo;
if (combobox.selectedIndex <= 0) {
alert("obbligatorio");
combobox.focus();
combobox.selectedIndex = 0;
combobox.select;
}
}
</script>
</head>
<body>
<form name="form1">
<select name="combo" size="3">
<option>
<option>1
<option>2
</select>
<input type="button" value="test()" onclick="test()">
</form>
</body>
</html>