Select fields (lists)

May 12, 2010 at 11:12 PM
Edited May 12, 2010 at 11:17 PM

Is it possible to validate list without using field with an empty value? Let's say if nothing is select, message box appears.

I was trying but without success. Thanks in advance.

BTW, I really like this script ;)

May 14, 2010 at 8:23 AM

Yes it is, the trick in (that I'm guessing you're using) is this:

<asp:DropDownList runat="server">
    <asp:ListItem Text="- select -" Value="" />
    <asp:ListItem>Option 1</aspx:ListItem>
    <asp:ListItem>Option 2</aspx:ListItem>

This renders as:

    <option value="">- select -</option>
    <option> value="Option 1">Option 1</option>
    <option> value="Option 2">Option 2</option>

This means you can have descriptive text while the value is still empty and will still trigger the message box. Does this help?

May 17, 2010 at 2:17 PM
Thanks for the answer but that works only with dropdown fields, not with lists. BTW, I'm using PHP ;)
May 18, 2010 at 5:12 AM

Thanks, I understand the situation now. Basically in the validator script change it to the code below so that it checks whether the value is empty string or null in the case of the listbox.

//if empty value only perform required validation
if ((jelm.val() == "" || jelm.val() == null) && jelm.find("input:radio:checked, input:checkbox:checked").size() == 0)
	return jelm.attr("require") ? "require" : "";