Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using jquery.validate.js for validation

and here is the code



XML
<!DOCTYPE html>
<html>
  <head>
    <title>Survey using jQuery Mobile
    </title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta charset="utf-8" />
    <link rel="stylesheet" href="jquery.mobile-1.1.0.min.css" />
    <link rel="stylesheet" type="text/css" href="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.min.css" />
    <link type="text/css" href="http://dev.jtsage.com/cdn/simpledialog/latest/jquery.mobile.simpledialog.min.css" rel="stylesheet" />
    <link type="text/css" href="http://dev.jtsage.com/jQM-DateBox/css/demos.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" media="screen" href="css/screen.css" />
<script src="js/jquery-latest.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/jquery.mobile-1.1.0.min.js"></script>
<script  src="http://dev.jtsage.com/jquery.mousewheel.min.js"></script>
<script src="http://dev.jtsage.com/cdn/datebox/latest/jquery.mobile.datebox.min.js"></script>
<script src="http://dev.jtsage.com/cdn/datebox/latest/jqm-datebox.mode.flipbox.min.js"></script>
<script  src="http://dev.jtsage.com/cdn/simpledialog/latest/jquery.mobile.simpledialog.min.js"></script>
<script src="js/jquery.validate.js" type="text/javascript"></script>
<script src="js/jquery.metadata.js" type="text/javascript"></script>
<script type="text/javascript">
    /*$(document).ready(function () {
    $("#submit").click(function () {
    var number = $("input[@name=radio-choice]:checked").val();
    alert((number));
    return false;
    });
    });*/
    $.metadata.setType("attr", "validate");


        $.validator.setDefaults({
        submitHandler: function() {
            alert("submitted!");
        }
    });

    $(document).ready(function() {
    $("#pet").validate();

});

 
</script>
    <style type="text/css">
    .block { display: block; }
     label.error { display: none; }
    </style>
  </head>
  <body >
    <div data-role="page" id="next" data-theme="a" >
      <form id="pet" class="cmxform" name="pet" method="post" target="_self">
        <fieldset data-role="controlgroup" >
          <legend>Choose a pet:
          </legend>
          <input type="radio" name="radio-choice" id="radio-choice-1" value="cat" validate="required:true"  />
          <label for="radio-choice-1">Cat
          </label>
          <input type="radio" name="radio-choice" id="radio-choice-2" value="dog"  />
          <label for="radio-choice-2">Dog
          </label>
          <input type="radio" name="radio-choice" id="radio-choice-3" value="hamspter"  />
          <label for="radio-choice-3">Hamster
          </label>
          <input type="radio" name="radio-choice" id="radio-choice-4" value="lizard"  />
          <label for="radio-choice-4">Lizard
          </label>
          <label for="radio-choice" class="error">Please select your gender</label>
        </fieldset>
        <input id="submit" type="submit" value="Validate " />
      </form>

      <div id="Msg">
      </div>
      <div data-role="footer" data-theme="c">            <h1>This is licenced Product</h1>
      </div>
    </div>
  </body>




validation is working perfectly if not selected a radio button .but the error message is not hidden once i select the option.I am using html5 and jquery mobile framework.


can anyone help me on this ?
Posted
Updated 20-Jul-12 22:07pm
v2

1 solution

That is because one of the jquery scripts puts a
<label for="radio-choice" class="error" style="display: inline; ">Please select your gender</label>

style="display: inline; " inside of the label when you click on validate while you have no radio button selected.

And I think that the style attribute takes precedence over the style sheet definition.
A way to solve this would be to add this code:

$(function () {
    $('input:radio').click(function () {
        $("label").attr("style", "");
    });
});


after the pet validation function, so it would look like this:

$(document).ready(function () {
    $("#pet").validate();
});

$(function () {
    $('input:radio').click(function () {
        $("label").attr("style", "");
    });
});


I tested it; it works.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900