0

i am writing jquery validation code and i want to add a div just before the label with a class name. i was unable to do so. So i found to add a wrapper in that label and also found to add class on that wrapper here [second answer] but it too didnt worked out. the page just redirects.

According to that answer i did like this:

$('#frm_product_info').validate({
    wrapper: "div class='abc'",
    rules:{
        lens_type:{
            required:true   
        },
        color:{
            required:true   
        }
    },
    messages:{
        lens_type:{
            required:"Please select a lens type."
        },
        color:{
            required:"Please select a frame color."
        }
    }
});

so please can any one help me to add a div before that label..or figure it out why the above code is not working if it is correct.

More codes

HTML

<form name="frm_product_info" id="frm_product_info" method="post" action="http://192.168.1.3/optic/site/cart_steps/steps/">
    <h3 class="margin_bottom">Select Lens Type</h3>
 <input type="radio" name="lens_type" value="4"/> Progressive<br/>
 <input type="radio" name="lens_type" value="3"/> Bifocal<br/>
 <input type="radio" name="lens_type" value="2"/> Single Vision Distant<br/>
 <input type="radio" name="lens_type" value="1"/> Single Vision Reading<br/>

     <input type="submit" value="Buy Now" class=" btn btn_buy_now"/>
</form>

SCRIPT

<script type="text/javascript" src="http://192.168.1.3/optic/js/jquery.validate.js"></script>
<script>
$(document).ready(function(){
$('#frm_product_info').validate({
    wrapper: "div",
    rules:{
        lens_type:{
            required:true   
        },
        color:{
            required:true   
        }
    },
    messages:{
        lens_type:{
            required:"Please select a lens type."
        },
        color:{
            required:"Please select a frame color."
        }
    }
});
});    
</script>
Community
  • 1
  • 1
Robz
  • 1,140
  • 3
  • 14
  • 35
  • Could you provide a more complete example with the html code? If you are redirected it seems your validation is not executed or it passes. – Jens Jun 11 '13 at 12:09
  • i have updated my codes. please have a look – Robz Jun 11 '13 at 12:16

1 Answers1

0
<script>
$(document).ready(function(){
$('#frm_product_info').validate({
  errorLabelContainer: "#error_place",
    wrapper: "div",
    rules:{
        lens_type:{
            required:true   
        },
        color:{
            required:true   
        }
    },
    messages:{
        lens_type:{
            required:"Please select a lens type."
        },
        color:{
            required:"Please select a frame color."
        }
    }
});
});    
</script>
<form name="frm_product_info" id="frm_product_info" method="post" action="http://192.168.1.3/optic/site/cart_steps/steps/">
    <h3 class="margin_bottom">Select Lens Type</h3>
<div id="error_place"></div>
 <input type="radio" name="lens_type" value="4"/> Progressive<br/>
 <input type="radio" name="lens_type" value="3"/> Bifocal<br/>
 <input type="radio" name="lens_type" value="2"/> Single Vision Distant<br/>
 <input type="radio" name="lens_type" value="1"/> Single Vision Reading<br/>

     <input type="submit" value="Buy Now" class=" btn btn_buy_now"/>
</form>
user2439722
  • 39
  • 1
  • 8