Solved

Does anyone know how to get Validity javascript plugin to work with a radio button?

Posted on 2010-09-03
5
524 Views
Last Modified: 2012-05-10
I just found this Validity plugin:

http://validity.thatscaptaintoyou.com/

which states it does conditional validation but I cant figure out what the syntax is to get it to work with a radio button?

Can someone tell me if it does do conditional validation with a radio button and if so please give me an example on the net to follow.

Also If validity does not do conditional validation with radio buttons can you please point me in the right direction?

Thanks!
0
Comment
Question by:HudsonMarine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 22

Expert Comment

by:kadaba
ID: 33597966
http://validity.thatscaptaintoyou.com/Demos/index.htm

Depends on what kind of conditional validation you need to do on the radios.
0
 
LVL 1

Author Comment

by:HudsonMarine
ID: 33598808
where at least one radio button is required and one out of several check boxes are required.

I cant find a definite javascript plugin that will validate based on this criteria.
0
 
LVL 22

Accepted Solution

by:
kadaba earned 500 total points
ID: 33599565
I put up a simple example using the documentation. For radio buttons make one of them default selected so that will avoid the validation. If not follow the same code, just replace the checkbox with radio. They will work the same way.

<html>
    <head>
        <title>Conditional</title>
        <link rel="Stylesheet" type="text/css" href="jquery.validity.css" />
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="jquery.validity.js"></script>
        <script type="text/javascript">
            $(function() { 
                $("form").validity(function() 
				{ 
					var fields = $("input[name='maillist']").serializeArray();
					var isNotChecked = true;
					
					if (fields.length == 0) 
					{
						isNotChecked = false;
					}
					
                   $("#choice")
						.assert(
							(isNotChecked), 
							"Please select at least one choice"
						);

                });
            });
        </script>
    </head>
    <body>
        <form action="conditional.htm" method="get">	
			<div id="choice">
			</div>
			<div>
			Choice1<input type="checkbox" id="maillist1" name="maillist" /><br>
			Choice2<input type="checkbox" id="maillist2" name="maillist" /><br>
			Choice3<input type="checkbox" id="maillist3" name="maillist" /><br>
			Choice4<input type="checkbox" id="maillist4" name="maillist" /><br>
			</div>
            <input type="submit" value="Submit" />
        </form>
    </body>
</html>

Open in new window

0
 
LVL 1

Author Comment

by:HudsonMarine
ID: 33640053
your example works when validating only the radio button,  but I am having trouble incorporating this with multiple conditional validations which is the ultimate goal.    With the script below I see that the validation is running on submit (alert messages appear on the screen) but then the form continues the submit operation without stopping. Please advise where my syntax has gone wrong.
$(function() 
	{ 
        $("form").validity(function() 
		 { 
			
			 if ($("#_2B_Industrial_Operations").attr("checked")) 
				{
					var fields = $("input[name='_2B_IO']").serializeArray();
					var isNotChecked = true;
							
							if (fields.length == 0) 
							{
								isNotChecked = false;
							}
							
						  $("#choice")
								.assert(
									(isNotChecked), 
									"Please make a selection");
							
					if ($("#_2B_IO_3").attr("checked")) 
						{
			
						$("#_2B_IO_Other_field")
						.require()          
						.maxLength(50);
						
						}			
				}
				
			if ($("#_2C_Ballast_Water_Treatment").attr("checked")) 
						{
							$("#_2C_BWT_Derivitives")
								.require("Value is required.")
								.maxlength(50);
						}
        });
    });

Open in new window

0

Featured Post

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

623 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