views:

34

answers:

1

Hi,

I am using javascript to validate user input on my aspx page. I am easily able to validate textboxes and dropdown list for differenet scenarios.

Now, on one of my dropdown lists (for country), I need to check if it is an allowed country or not for a particular service. I have stored the valid country list in a static property. Is there a way to validate my dropdownlist selected value against that static property?

Any help would be much appreciated.

Cheers, Abhi.

function validateService(source, args) 
{
            var country = document.getElementById('<%= ddDestCountry.ClientID %>');
            var service = document.getElementById('<%= ddService.ClientID %>');
// Get allowed country list from my static class
            var countryList = document.getElementById('<%= StaticProperties.EUCountryList %>');

            if (service.value == "P") 
            {
               // I want to do something like this
                if (!countrylist.Contains(country.value)) 
                {
                    args.IsValid = false;
                }
                else {
                    args.IsValid = true;
                }
            }
            return;
        }

Update(Additional Information): The static property is read-only so it cannot be tampered with from the page.

+1  A: 

This validation should be done on the server side and not on the client side. there's nothing preventing me from using greasemonkey to change your static list while I have your page up and inserting "Oz" as a country in your "validating" list

FatherStorm
It is a read-only static property, so it cannot be altered with from the aspx page. Is it still a bad idea to handle it on client-side? Is there another better way to handle this on client-side?
Abhi
+1 It should be handled on the server side, at least. Client side validation is extra. What if the user turns off javascript in their browser? It's nice to have client side validation so the user doesn't have to post back the page, however you must have server side validation just to make sure the information is actually valid.
RexM
Using a bolt-on mod engine like greasemonkey, there is no such thing as "Read Only". what Greasemonkey does is attach additional javascript to the page AFTER it has been loaded on the client side. Once that is done, any javascript in the greasemonkey script can do whatever it wants to the contents of the DOM. you can't lock the browser on the client side. as an example, here's a greasemonkey script to get around the rapidshare download-delay that relies on a read-only value to calculate time left before enabling download link. http://userscripts.org/scripts/show/10380
FatherStorm