473,584 Members | 2,897 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript custom validator problem on DropDownList

Hi,

I'm pretty new to javascript and i'm struggling to get a custom
validator working.

I have a dropdownlist populated by a datareader, the top value of which
is always "Please Select..." at index 0.

How can i code a validator to be invalid if "Please Select..." is
selected, but valid for any other value?

Here is my attempt:

function validateSurgeon NameDDL(oSrc, args)
{
args.IsValid = ([surgeonNameDDL. SelectedIndex].Value != "0");
}

However, this comes back invalid, for all selection.

Thanks.

Aug 11 '05 #1
1 4694
Assimalyst wrote:
Hi,

I'm pretty new to javascript and i'm struggling to get a custom
validator working.

I have a dropdownlist populated by a datareader, the top value of which
is always "Please Select..." at index 0.

How can i code a validator to be invalid if "Please Select..." is
selected, but valid for any other value?

Here is my attempt:

function validateSurgeon NameDDL(oSrc, args)
{
args.IsValid = ([surgeonNameDDL. SelectedIndex].Value != "0");
}


function somethingSelect ed(dropdownlist ){
return dropdownlist.se lectedIndex>0;
}

function validateForm(fo rm){
var msg="";
if(!somethingSe lected(form.SEL ECTNAMEHERE)) {
msg+="Please select a surgeon\n";
}

....
if(msg){alert(m sg);return false;}
return true;
}
Mick
Aug 11 '05 #2

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

Similar topics

0
2222
by: Tom Pearson | last post by:
I create controls and validators dynamically dependent on data at runtime. I create the control then the relevant validator(s) for it assigning the Control.ID as the control to validate. These controls and validators are then added to a table for display to the user. This code did seem to work originally, but now does not amd I am stumped as to...
2
3896
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow javascript checks for things like valid e-mail addresses or phone numbers (without having to add a separate control for validation). One idea I...
2
9856
by: Dot net work | last post by:
Hello. Say I have a .net textbox that uses a .net regularexpressionvalidator. If the regular expression fails, is it possible to launch a small client side javascript function to do something, such as change the border color of the textbox to red? That would look quite nice: if the expression fails, the red validator text is shown, plus...
0
984
by: Vi | last post by:
Hi, I have two pairs of a DropDownList and TextBox Controls and for each of the pair I have a CustomValidator that makes sure that at least one of the two (DropDownList or TextList) has a value. When I submit the form, the OnServerValidate method for the first pair of controls (DropDownList and TextList) fires, but for the second pair does...
1
3249
by: IkBenHet | last post by:
Hello, Currently I am using a large input form on a website that is based on ASP and JavaScript. Depending on the values that are filled in by the user the forms does a refresh and makes other input fields available to fill in. I use the JavaScript OnChange function (=clientside) that creates a querystring and does a refresh of the page....
3
5354
by: useenmelately | last post by:
Hello, I am working with asp.net 2.0 and have run into a problem with the custom validators. The client validation functions were originally written in vbscript, but as this is not compatible with many browers i changed them to javascript. This is where the problem came about, the exact same functions written in javascript dont work!!...
2
3763
by: Bas Groeneveld | last post by:
Hi I want to detect a name in brackets - eg (Bas) - being selected in a dropdownlist. I intended to use the RegEx validator with ^\(.*\)$ which should work. My problem is that the value of the dropdownlist is not the same as the displayed text (ie it is the ID of the selected item) and the validator appears to operate on the list value.
0
1569
by: tsw_mik | last post by:
I have created a custom control. It has: -label -button -list of textboxes -list of dropdownlists. I want to use a custom validator to perform some validation, but somehow I can't fo it. The code looks like this: public class ColumnSelector : Panel {
1
376
by: Joey | last post by:
asp.net 2/C#/VS2005 I want to create a validator that will be able to check a drop-down list box to make sure that the first item (index 0) is NOT selected. Does anyone have any ideas about how to do this?
0
8190
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8331
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7940
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8200
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6590
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5705
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2336
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1441
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.