-3

I have this textbox with the button and submitting the data using ajax

<input type="password" id="password" />
<button id="addaccount" onclick="showload();">Add</button>

the showload(); indicates the loading of the page, it shows the pure white background with 50% opacity on it and a loading .gif in the center.

now how can I reset the password textbox in the javascript?

$(document).ready(function(){
    $("#addaccount").click(function(){
        var password = $("#password").val();
            $.ajax({
                method: "POST",
                url: "auth_adduser.php",
                data: {
                    password:password
                    },
                success: function(data){
                    $("#successresult").html(data);
                }
            });

    });
});

thanks in advance

Marverick M.
  • 124
  • 1
  • 15

9 Answers9

4

you can clear the input value by setting it to an empty string

$("#password").val("")
skav
  • 1,400
  • 10
  • 16
3

Get element by id and reset the value.

$('#password').val('');

If you want to reset entire form then simply trigger reset event. This will only work if the elements are inside a form.

$('#password').closest('form').trigger('reset');
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
2

After succesfull ajax execution $("#password").val(""); reset password

$(document).ready(function(){
    $("#addaccount").click(function(){
        var password = $("#password").val();
            $.ajax({
                method: "POST",
                url: "auth_adduser.php",
                data: {
                    password:password
                    },
                success: function(data){
                    $("#successresult").html(data);
                  $("#password").val("");
                }
            });

    });
});
prasanth
  • 22,145
  • 4
  • 29
  • 53
1

Changing value of an input using jQuery

$("#password").val('');

Resetting = setting value to ' '

Luka Kerr
  • 4,161
  • 7
  • 39
  • 50
santosh
  • 118
  • 6
1

You can do with the same click event,

$(document).ready(function(){
  $("#addaccount").click(function(){
    var password = $("#password").val();
        $.ajax({
            method: "POST",
            url: "auth_adduser.php",
            data: {
                password:password
                },
            success: function(data){
                $("#successresult").html(data);
                $("#password").val(''); //reset password field.
            }
        });

   });
});
Samir
  • 1,312
  • 1
  • 10
  • 16
1

Use Following in Success Function: In Jaavascript: Use

document.getElementById("password").reset();

In Jquery :

$("#password")[0].reset();

See Full Code :

$(document).ready(function(){
    $("#addaccount").click(function(){
        var password = $("#password").val();
            $.ajax({
                method: "POST",
                url: "auth_adduser.php",
                data: {
                    password:password
                    },
                success: function(data){
                    $("#successresult").html(data);
                    $("#password")[0].reset();
                }
            });

    });
});
Sachin Sanchaniya
  • 996
  • 1
  • 8
  • 16
0

Simple. After you do all of your processing, enter:

$("#password").val("")

If you are using jQuery.

Adam Mikacich
  • 137
  • 1
  • 1
  • 13
0

Almost possible ways :D

$("#password").val("");
$("#password").attr("value", "");

$("#password")[0].value = "";
$("#password")[0].setAttribute("value", "");


document.getElementById("password").value = "";
document.getElementById("password").setAttribute("value","");
Mamdouh Saeed
  • 2,302
  • 1
  • 9
  • 11
0

using jquery

$('#password')
.val('')
.attr('value', '');

using javascript

document.getElementById("password").value = "";
document.getElementById("password").setAttribute("value","");
Sreepathy Sp
  • 408
  • 2
  • 6
  • 21