Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show message in hidden field using jQuery?

I have an input field that stores vales for checking a condition.I changed this to hidden: if the condition is false I need to show a message.

If the field is hidden,the message is not shown.

html

 <input type="hidden" id="year1_req_fund_hidden" name="year1_req_fund_hidden">

jquery

#wizard5').validate(
{
  rules: {

       year1_req_fund_hidden:{
                    //required:true,
                     number:true,
                     validate_check: [$('#year1_grand_amt').val(),'1'],
                    },
          }, 
 });


 $.validator.addMethod("validate_check",
  function(value, element, params) {
  if(params[0]!=''){
  if(value == params[0]) {
     return true;
     }
   }
  },
 $.format("The total amount requested does not match with grant amount {0} requested in Q1.11 in year {1} .")

  );
like image 984
robins Avatar asked Dec 07 '25 13:12

robins


2 Answers

$('#wizard5').validate({
   ignore:'', // or ignore: []
   rules: {

         year1_req_fund_hidden:{
                //required:true,
                 number:true,
                 validate_check: [$('#year1_grand_amt').val(),'1'],
           },
     }, 
 });

Your code should be as per above

It will work for you. By default, jQuery Validation ignores hidden fields. http://prntscr.com/g0urkk

like image 181
Brijesh Borad Avatar answered Dec 09 '25 02:12

Brijesh Borad


This way can solve your problem...!

if (!$('input').attr('id') == null) {
    //check your condition according to you
    //your action here
} else {
    //show your message in .hidden div
    $('.hidden').fadeIn('slow').html('Message');
}
.hidden {display: none;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="hidden" id="year1_req_fund_hidden" name="year1_req_fund_hidden">
<!-- Place below div where you want to show your message -->
<div class="hidden"></div>
like image 31
Rohit Sharma Avatar answered Dec 09 '25 02:12

Rohit Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!