Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Ensuring a listbox has at least one value in it

Reply
Thread Tools

Ensuring a listbox has at least one value in it

 
 
Simon
Guest
Posts: n/a
 
      05-25-2004
Hi

Does anyone know how I can be sure that a listbox has a value in it without
doing a post back?

If I attach a required field validator it will only allow the page to submit
if I actually highlight one of the items in the listbox to validate.

I'm really hoping that this can be done somehow using the required field
validator. I've looked at the custom validator control but that looks like
way to much hassle especially seeing as I don't know javascript

Thanks to anyone who can help

Simon


 
Reply With Quote
 
 
 
 
Raterus
Guest
Posts: n/a
 
      05-25-2004
Well you are creating the contents for the listbox from your server-side script right? Can't you check it there? Unless the user is dynamically adding values to this listbox, which if that is the case, you probably created that, and therefore you know just a little about javascript . I don't see how a requiredfieldvalidator would work in this case, if they don't actually have to select a value. You'll have to make your own javascript to check this, shouldn't be too hard.

"Simon" <sh856531@microsofts_free_email_service.com> wrote in message news:%(E-Mail Removed)...
> Hi
>
> Does anyone know how I can be sure that a listbox has a value in it without
> doing a post back?
>
> If I attach a required field validator it will only allow the page to submit
> if I actually highlight one of the items in the listbox to validate.
>
> I'm really hoping that this can be done somehow using the required field
> validator. I've looked at the custom validator control but that looks like
> way to much hassle especially seeing as I don't know javascript
>
> Thanks to anyone who can help
>
> Simon
>
>

 
Reply With Quote
 
 
 
 
Vidar Petursson
Guest
Posts: n/a
 
      05-26-2004
Hi,

For multiple you can
var e = document.forms[0].SELECTNAME;
var b = 0;
for(i=0;i<e.length;i++)
{
if(e.options[i].selected) b++;
}
if(!b) alert("Select something");


First option a no go
if(e.selectedIndex < 1 ) alert("Select something");

More info
http://msdn.microsoft.com/library/de...ence_entry.asp

--
Best Regards
Vidar Petursson
==============================
Microsoft Visual: Scripting MVP 2000-2004
http://www.icysoft.com/
http://www.deus-x.com/ Instant e-commerce
http://www.microsoft.com/technet/scriptcenter/
Playground: http://213.190.104.211/ ( IE 5.5+ only )

No matter where you go there you are
==============================
"Simon" <sh856531@microsofts_free_email_service.com> wrote in message
news:%(E-Mail Removed)...
> Hi
>
> Does anyone know how I can be sure that a listbox has a value in it
> without
> doing a post back?
>
> If I attach a required field validator it will only allow the page to
> submit
> if I actually highlight one of the items in the listbox to validate.
>
> I'm really hoping that this can be done somehow using the required field
> validator. I've looked at the custom validator control but that looks like
> way to much hassle especially seeing as I don't know javascript
>
> Thanks to anyone who can help
>
> Simon
>
>



 
Reply With Quote
 
Simon Harvey
Guest
Posts: n/a
 
      05-26-2004
Thanks guys

Simon


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need regular expression for at least 7 characters and at least 1 special chatacter AAaron123 ASP .Net 0 10-03-2008 01:25 PM
How to validate that at least one text box has input Homer ASP .Net 1 08-28-2007 11:56 PM
Ensuring at least one form element has been used DoomedLung Javascript 1 09-28-2006 04:43 PM
Ensuring directory deletion has complete Mark Java 1 12-08-2005 02:05 PM
Ensuring a listbox has at least one value in it Simon ASP .Net Web Controls 3 05-26-2004 02:18 PM



Advertisments