2

I have a form

   <div class="componenti_attive riquadro" style="display: block;">
<h2>LE COMPONENTI POSITIVE DEL TUO BILANCIO</h2>
<p class="title redd1 has-success" style="display: block;">Reddito mensile del primo componente
<input name="reddito1" type="text" class="form-control num positivi valid" placeholder="Redditi primo componente ..." data-validation="number" data-validation-error-msg="Inserisci solo numeri senza virgole e decimali!" data-validation-optional="true" style=""></p>

<div class="btnPrint indietro1"><h2 class="stamp printMe">INDIETRO</h2></div>
<div class="btnPrint avanti2 avant"><h2 class="stamp printMe">AVANTI</h2></div>
</div>

I have jquery Validator (the input object must be number) In case of error must be appear a span object (class form-error):

<p class="title redd_altri1 has-error" style="display: block;">Indicare il totale degli altri redditi (es. pensioni, indennità, rendite, etc.)
<input name="altri_redditi" type="text" class="num positivi form-control error" placeholder="Inserisci qui il totale mensile degli altri redditi ..." data-validation="number" data-validation-error-msg="Inserisci solo numeri senza virgole e decimali!" data-validation-optional="true" style="border-color: red;"><span class="help-block form-error">Inserisci solo numeri senza virgole e decimali!</span></p>

I would like that, if this object is displayed so the div class avant is hide

<div class="btnPrint avanti2 avant"><h2 class="stamp printMe">AVANTI</h2></div>

I have this js

$form.on('change', '.num',  function ()
   {var $errori = $('.form-error').length;
if ($errori > 0)
    {$('.avant').hide();}
    else {$('.avant').show();}
            });

but it doesn't work!!

1
  • can you please add a fiddle Commented Apr 8, 2014 at 15:25

1 Answer 1

1

This is just a suggestion,
but if you want to make disappear the div avant if the number entered in the fields is incorrect, you can obtain the result even without plugin
you can use a regex.(fiddle)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $('.avant').hide()
    var tot=/^[+-]?\d+(\.\d+)?([eE][+-]?\d+)?$/
    $('input').on('keyup',function(){
        var str = $(this).val();
        if(tot.test(str)) {
          $('.form-error').hide()
           }else{$('.form-error').show()}
           if($('.form-error').is(':visible')){
               $('.avant').hide()
               }else{
                $('.avant').show()   
                }
        })
})
</script>

not having your complete code I had to opt for this solution. ..ciao alla prossima.

Sign up to request clarification or add additional context in comments.

1 Comment

$(document).ready( function() { var ck_validate = /^$|^[0-9]{1,45}$/ $('#bilancio_familiare').on('keyup', '.num', function () { var valore = $('.num').val(), $errori = $('.form-error').length; if ((!ck_validate.test(valore))||($errori!=0)) {$('.avant').hide();} else {$('.avant').show();} }); }); It works! thanks for idea!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.