469,282 Members | 1,637 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

check required in a select

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
2 3033
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
"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.

Similar topics

4 posts views Thread by Dmitri Shvetsov | last post: by
3 posts views Thread by frizzle | last post: by
1 post views Thread by Michelle A. | last post: by
4 posts views Thread by tshad | last post: by
11 posts views Thread by Naeem | last post: by
3 posts views Thread by Search & You Will Find | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.