POTHYSTALIN POTHYSTALIN - 5 months ago 29
HTML Question

Reseting textbox values after successful ajax response

I am now trying to reset the values of textbox after the ajax request was succcessfully completed.
I tried something like this

$('#text1').val("");
$('#text2').prop('value','');


But woludn't works.
These all are works in console..

<script type="text/javascript" src="/Includes/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$('#btn').click(function(){
jQuery.ajax({
url:"validation.cfc",
data:{method:'db_validation',fname:$('#text1').val(),Email:$('#text2').val()},
type:"POST",
success:function(html){
//what code should be written to clear textbox values after successful ajax response
//$('#text1').val(""); ---> This code was not working
$('#para').html(html);//even this code was executed.
}
});
});
});
</script>
<form>
<p id="para"></p>
<input id="text1" name="txtBox1" type="text"><br />
<input id="text2" name="txtBox2" type="text"><br />
<input type='button' name='Button' value='Add User' id="btn"/>
</form>

Answer

use the following , It empties textbox.

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

U may have problem in ur code.

If any problem refer HERE

Also jQuery API