By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,619 Members | 1,534 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,619 IT Pros & Developers. It's quick & easy.

check required in a select

P: n/a
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();
}
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Sat, 09 Oct 2004 10:43:38 GMT, SAN CAZIANO <al**********@tin.it> wrote:

[snip]
if (combobox.SelectedIndex==0 || combobox.SelectedIndex==-1)


Javascript is case-sensitive. The selectedIndex property starts with a
lowercase 's'.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

P: n/a
"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>


Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.