Advertisement:

Author Topic: Hi guys how to add a error message on this?  (Read 323 times)

Rhoda

  • Jr. Member
  • **
  • Posts: 92
Hi guys how to add a error message on this?
« on: April 18, 2017, 08:52:42 am »
Hi guys how do i add a error message on this script in this line

Code: [Select]
$('input[name="s_postby"]').attr("required", true); // put the id of the input field that you whant required


Code: [Select]
<script type="text/javascript">
$('#catId').change(function(){
    if( $('#catId').val() == "28" || $('#catId').val() == "29" || $('#catId').val() == "30" || $('#catId').val() == "31")
    {
    $("#postby").hide();  // change Posted By with ID you give to the div
$('input[name="s_postby"]').attr("required", false); // put the id of the input field that you whant required
    }else
    {
    $("#postby").show(); // change Posted By with ID you give to the div
$('input[name="s_postby"]').attr("required", true); // put the id of the input field that you whant required
    }
});
</script>

I need that the error will appears same way like the other error messages!

Code: [Select]
<script type="text/javascript">
    $(document).ready(function(){
        // Code for form validation
        $("input[name=s_postby]").attr({
            rules: {
                yourEmail: {
                    required: true,
                    email: true
                }
            },
            messages: {
                yourEmail: {
                    required: "Email: this field is required.",
                    email: "Invalid email address."
                },
                message: {
                    required: "Message: this field is required.",
                    minlength: "Message: this field is required."
                }
            },
            errorLabelContainer: "#error_list",
            wrapper: "li",
            invalidHandler: function(form, validator) {
                $('html,body').animate({ scrollTop: $('h1').offset().top }, { duration: 250, easing: 'swing'});
            },
            submitHandler: function(form){
                $('button[type=submit], input[type=submit]').attr('disabled', 'disabled');
                form.submit();
            }
        });
    });
</script>

hope you can help!

Thanks