Jamie
With a single select box, an option is always selected. In a multi select
box, nothing is selected untill you select it, so you will need to loop
through the options to see if any are selected
I suggest to create a seperate function to handle that.
<script>
function hasSelected(obj,form)
{
thisSelectBox = document[form][obj];
returnVal = false;
for (i=0; i < thisSelectBox.options.length; ++i)
{
if (thisSelectBox.options[i].selected == true)
{returnVal = true; break;}
}
return returnVal;
}
</script>
that should return true or false when you call that function (not tested
though). you need to pass in the form object and the select box object.
Hope that helps
Regards
Steve Onnis
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Jamie
Strachan
Sent: Wednesday, July 30, 2003 3:01 PM
To: CFAussie Mailing List
Subject: [cfaussie] OT: Javascript validation help
Could someone please help me in regards to a simple javascript problem i am
having. I have a select box that has the multiple option activated. When
the user submits the form i need to check that a value has been selected in
the select box. I have been able to do this with a normal select box not
when the multiple option is available.
Here is what i have so far, i just cant get it to work.
Any feedback welcome.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if
(document.frmSendMsg.Destination.options[document.frmSendMsg.Destination.sel
ectedIndex].value == -1) {
alert ('Please select a recipient for the message');
document.frmSendMsg.Destination.focus();
return false;
}
---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
MX Downunder AsiaPac DevCon - http://mxdu.com/
---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
MX Downunder AsiaPac DevCon - http://mxdu.com/