Repeating error code from jQuery -


the below code works correctly when click submit on user login form incorrect user name , password error:

incorrect informatiın

then click submit again incorrect values , error message repeats on , over. because of div strangely expands. how can fix this?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
$("#giris").submit(function (event) {     var kullanici_adi = $("#kullanici_ad").val();     var sifre = $("#sifre").val();     $.ajax({         type: "post",         url: "girisislemi.php",         data: {             kullanici_adi: kullanici_adi,             sifre: sifre         },         datatype: "json",         success: function (data) {             if (data.tip === 'yonetici') {                 window.location.href = "yonetici.php";             }             if (data.tip === 'kullanici') {                 window.location.href = "kullanici.php";             }             if (data.tip === 'error') {                 $('input[type=text]').css("border", "3px solid red");                 $('input[type=password]').css("border", "3px solid red");                 $('#giris').after("<font><p>incorrect information </p><font>");                 $('font').css("color", "red");             }          }      });     event.preventdefault(); }); 

the issue due use of after() add new content each time it's run. instead, check see if error has been shown:

if (data.tip === 'error') {     $('input[type=text], input[type=password]').addclass('login-error');     if (!$('p.login-error').length)         $('#giris').after('<p class="login-error">incorrect information </p>'); } 

also note <font /> element outdated, , shouldn't used more, , should set styling rules in classes in stylesheet , using add/removeclass instead of setting inline css().

input.login-error {     border: 3px solid red; } p.login-error {     color: red; } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -