I'm working on a login/register page, in which the forms switch depending on whether the user decide to login or register.
I'm trying to empty all of the <input>
when the user switch forms.
I can get to erase all the contents of the <input>
fields, but that's including the <input type="submit">
, thus also erasing the submit button's message.
Here's what I tried to do to select every input except the submit one, but it doesn't empty the fields anymore :
$('.message a').click(function(){
$('form').animate({height: "toggle", opacity: "toggle"}, "slow");
$(':text, :password, :email').each(function(){
$(this).val('');
});
});
And here's what I tried before, selecting all input, also erasing the "submit" one :
$('.message a').click(function(){
$('form').animate({height: "toggle", opacity: "toggle"}, "slow");
$('input').each(function(){
$(this).val('');
});
});
Also, here's the html :
<div class="form">
<form class="register-form" autocomplete="off">
<input type="text" placeholder="nom" name="name_register"/>
<input type="text" placeholder="prenom" name="last_name_register"/>
<input type="password" placeholder="mot de passe" name="password_register"/>
<input type="email" placeholder="adresse email" name="email_register"/>
<input type="submit" value="Inscription"/>
<p class="message">Already registered? <a href="#" class="register">Sign In</a></p>
</form>
<form class="login-form">
<input type="email" placeholder="adresse email" name="email_login"/>
<input type="password" placeholder="mot de passe" name="password_login"/>
<input type="submit" value="Connexion"/>
<p class="message">Vous n'êtes pas enregistré? <a href="#" class="login">Créer un compte</a></p>
</form>
</div>
$("input:not([type='submit'])").each
if i understand your requirments correctly following will help you
$('.message a').click(function() {
$('form').animate({
height: "toggle",
opacity: "toggle"
}, "slow");
$('input[type=text], input[type=email], input[type=password]').each(function() {
$(this).val('');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</div>
You should use this selector:
$("input:not([type=submit])")
User the following instead.
$('.message a').click(function(){
$('form').animate({height: "toggle", opacity: "toggle"}, "slow");
$('input[type=text], input[type=password], input[type=email]').each(function(){
$(this).val('');
});
});
try $('.register-form')[0].reset();
it will reset form values