Solved

How to find control in asp.net javascript client custom validator

Posted on 2008-10-14
1
1,848 Views
Last Modified: 2012-06-27
Goal is to validate on the client side (javascript) that a listbox has either no selections or at least a minimum number of rows selected.
I can sneak in the minimum number of rows, but need assistance finding the listbox, given the source or args parameters.


<script type="text/javascript" >

  function cvAnswer_7_2_4MinLengthListBox_ClientValidate(source, args) {

    alert(source.id);

    alert(args.ControlToValidate);

    alert(source.ControlToValidate);

    alert('zero');

    var regex = /^\D*\d+_(\d+)_/;

    var result = source.id.match(regex);

    var minLength = parseInt(result[1], 10);

    var lbx = document.getElementById(source.id);

    alert(lbx);

    alert(lbx.options);

    alert(lbx.options.length);

    var selectedCount = 0;

    alert('two');

    var i;

    alert('three');

    for (i = 0; i < lbx.options.length; i++) {

      if (lbx.options[i].selected) {

        selectedCount++;

      }

    }

    alert('four');

    args.IsValid = (selectedCount >= minLength);

    alert('five');

    alert(args.IsValid)

  }

</script>

Open in new window

0
Comment
Question by:brotherbill999
1 Comment
 

Accepted Solution

by:
brotherbill999 earned 0 total points
Comment Utility
To find listBox, use: source.controltovalidate
Note that on Server side, it is ControlToValidate, but on javascript side it is all lowercase.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
updateParent() HTML Javascript 21 59
Safari SVG Image Problem 1 19
JavaScript error 1 33
angularjs controller not found 1 16
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now