Ensuring a listbox has at least one value in it

Discussion in 'ASP .Net' started by Simon, May 25, 2004.

  1. Simon

    Simon Guest

    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
    Simon, May 25, 2004
    #1
    1. Advertising

  2. Simon

    Raterus Guest

    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:%...
    > 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
    >
    >
    Raterus, May 25, 2004
    #2
    1. Advertising

  3. Hi,

    For multiple you can
    var e = document.forms[0].SELECTNAME;
    var b = 0;
    for(i=0;i<e.length;i++)
    {
    if(e.options.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/d...hor/dhtml/reference/dhtml_reference_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:%...
    > 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
    >
    >
    Vidar Petursson, May 26, 2004
    #3
  4. Simon

    Simon Harvey Guest

    Thanks guys

    Simon
    Simon Harvey, May 26, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Homer
    Replies:
    1
    Views:
    450
    Sherif Elmetainy
    Aug 29, 2007
  2. AAaron123
    Replies:
    0
    Views:
    588
    AAaron123
    Oct 3, 2008
  3. Simon

    Ensuring a listbox has at least one value in it

    Simon, May 25, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    131
    Simon Harvey
    May 26, 2004
  4. NotGiven
    Replies:
    5
    Views:
    171
    Thomas 'PointedEars' Lahn
    Feb 12, 2004
  5. DoomedLung
    Replies:
    1
    Views:
    93
    web.dev
    Sep 28, 2006
Loading...

Share This Page