P
P
PyChan2020-06-01 17:33:34
JavaScript
PyChan, 2020-06-01 17:33:34

How to add one jquery handler to two django ModelForm fields?

Handler:

$(document).ready(function() {
   $('#id_repeat_password').on('keyup', function(){
      var Value = $('#id_repeat_password').val();
      var Value1 = $('#id_password').val();
      if (Value != Value1)
      {
        $("#text").animate({opacity: "1"}, "fast");
      }
      else
      {
        $("#text").animate({opacity: "0"}, "fast");
      }
   });
});

The form
class SignUp(forms.Form):
    username = CharField(label='username', max_length=150,
                         widget=TextInput(attrs={'required': True, "class": 'input', 'type': "text"}))
    email = CharField(label='Username', max_length=150,
                      widget=TextInput(attrs={'required': True, "class": 'input', 'type': "text"}))
    password = CharField(label='Password', max_length=150,
                         widget=TextInput(attrs={'required': True, "class": 'input', 'type': "password"}))
    repeat_password = CharField(label='Repeat your password', max_length=150,
                                widget=TextInput(attrs={'required': True, "class": 'input', 'type': "password"}))

It is necessary that the handler be called both when entering in the password field and when entering in the repeat_password field. Please tell me how to do it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Pautov, 2020-06-01
@PyChan

$('[type="password"]')
// Или дать класс этим полям
$('.inputPassword')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question