473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Ensuring a listbox has at least one value in it

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
Nov 18 '05 #1
3 3013
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:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #2
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:%2****************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #3
Thanks guys

Simon
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: cannen | last post by:
This is a repost as I am down to the last hair on my head. I am using a listbox on a tab control on my mainform that has alisting of all records associated with form main record. when I select...
3
by: Stimp | last post by:
I have a listbox of values that I populate from a database. I want the user to be able to re-order the list (by first selecting an item and then clicking 'up' or 'down' buttons) and then save...
2
by: Dave | last post by:
Greetings, How can I access the selecteditem.value property for a listbox that is in a user control (.ascx) inside of my .aspx page? Thanks, -Dave
8
by: tshad | last post by:
I have a string that I read from my database: 1|8|5620|541 These are all values in my ListBox. I want to select each of these items (4 of them - but could be many more). At the moment I am...
3
by: joe | last post by:
I actually have 2 questions: 1) Is databinding the fastest way to load a listbox from sqlserver? speed is crucial and I want to make sure i'm populating it the fastest way i can 2) Also,...
11
by: John Dann | last post by:
I'm still struggling to find a way of reordering the items within the same single listbox with drag and drop. I think I've got the drag working but it's the drop code I can't figure out. What I...
1
by: lance2001 | last post by:
Hi, After viewing the entire Visual Basic 2005 Express Edition for Beginners video series, I have begun building a database driven application that will make use of listbox1 (multi-select)...
1
by: DoomedLung | last post by:
Hey, I'm currently developing an online work brief, where the user has to enter details regarding the project into a form. I've come to a section in the form where the user has the option of...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.