Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

client validation on click of checkbox in a nested repeater

Posted on 2008-10-30
6
Medium Priority
?
3,347 Views
Last Modified: 2013-11-11
I have a repeater which shows current month records from database based upon month and year selection from dropdownlist at the top of page. This repeater has 3 textboxes per row  (date of month) and a nested repeater. Nested repeater contains checkbox and is populated from database. I want to make sure using javascript and custom validators that at least one checkbox in each row should be selected.
0
Comment
Question by:Munawar Hussain
  • 4
  • 2
6 Comments
 
LVL 12

Expert Comment

by:techExtreme
ID: 22843548
Hello,
Looking from your description, you seem to have
for each outer repeater item,
  you hav 3 textboxes  and 1 child repeater  (which further down contains 1 checkbox).

But this means you only have 1 checkbox per item.
And you want to ensure all of these are selected?
I guess I'm missing something out here.
0
 
LVL 12

Author Comment

by:Munawar Hussain
ID: 22847693
In child repeater I have list of checkboxes and one of those checkboxes should be checked.
0
 
LVL 12

Accepted Solution

by:
techExtreme earned 2000 total points
ID: 22851252
Hello,
Got it, I have created a sample javascript for you, just paste it as a .html file and run locally and try pressing the submit button without selecting checkboxes in each row, it will give error and tell you that you have to select these many checkboxes atleast i.e. once per each row.

This is html and javascript , but looking at the code and html I have produced, you can easily port it in your repeater, just make sure you keep ids properly and change variables accordingly in this script.

Hope it solved your problem.

Happy Javascripting!

<html>
<body>
 
<form id="form1" >
<div id="_main" style="width:100px;">
 
<div id="div1" style="background-color:Gray;">
	<input type="CHECKBOX" id="chk_1" value="This...">
	<input type="CHECKBOX" id="chk_2" value="This...">
	<input type="CHECKBOX" id="chk_3" value="This...">
</div>
Group 2
 
<div id="div2" style="background-color:Gray;">
	<input type="CHECKBOX" id="chk_1" value="This...">
	<input type="CHECKBOX" id="chk_2" value="This...">
	<input type="CHECKBOX" id="chk_3" value="This...">
</div>
 
 
<input type="hidden" id="hdn1" value="div1,div2">
</div>
 
<input type="submit" value="submit" onclick="checkform()" >
</form>
</body>
</html>
 
<script type="text/javascript">
 
function checkform()
{
  var v_main  = document.getElementById("_main");
  var v_sub = v_main.getElementsByTagName('div');
  
  var i=0;
  var faultCounter=0;
  while(i<v_sub.length)
  {	
	var v_sub2 = v_sub[i].getElementsByTagName('input');
	var innerChecked=0;
        j=0;
	while(j<v_sub2.length)
	{
		if(v_sub2[j].checked==true)
		{
			innerChecked=1;
		}	
		j++;
	}
	
	if(innerChecked==0) //i.e. no checkbox is checked
	{
	  faultCounter = faultCounter + 1;
	}
	i++;
  }
 
  if (faultCounter>0)
  {
    alert("Atleast select one checkbox frome each row, " + faultCounter + " checkbox needs to be selected yet.");
  }
  else
  {
	alert("All O.K.");
  }
}
 
 
</script>

Open in new window

0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 12

Expert Comment

by:techExtreme
ID: 22851307
Also forgot to mention, after you get familiar with the script I posted above,
you will notice tht
there should be one single outer div element,

then elements like div1, div2 ... can probably be once per itemtemplate of repeater,
i.e. if you have two dataitems, you should render div1,div2...  , if you have three dataitems, your repeater shoudl produce div1,div2,div3 like that.

Now inside of these divs (div1, div2... ) you can have your checkboxes.
ids of checkboxes doesn't matter as of now.


You can use this logic with two repeaters, or 1 repeater,
its just how you arrange the divs and how they render dynamically!
0
 
LVL 12

Author Comment

by:Munawar Hussain
ID: 22851970
Hi techExtreme,

    Thanks for your time. I pasted above code in html file but when I click one checkbox from one row and dont check any from other row It prompts me with alert and then the checkbox I checked also looses selection. Why so ?

Regards,
Asif Hameed
0
 
LVL 12

Expert Comment

by:techExtreme
ID: 22852551
Its just html buddy. Once you prepare it with dynamic code and in aspx page , the session will be maintained there.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Suggested Courses

916 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