php - jquery not working with if statement -
i using jquery script ajax update method bound focus event of form element. works, first want check if form element not empty. that, function stops working. below code:
<script type="text/javascript"> if ($('#txt_updateone').val().trim().length > 0) { function single_change(txt_updateone) { $.ajax({ type: "post", data: { "txt_updateone": 1 }, url: "single_scorechange.php", success: function (data) { $('#listinscore').load(document.url + '#listinscore'); }, error: function (xhr) { alert("error"); } }); return false; } } </script>
txt_updateone textarea , onfocus event calls single_change function. when remove if..... on second line, works, want work if textarea not empty.
there 2 methods.
1) validate data @ place calling function.
2) validate data before sending ajax request using beforesend
.
<script type="text/javascript"> function single_change(txt_updateone) { $.ajax({ type: "post", data: { "txt_updateone": 1 }, url: "single_scorechange.php", success: function (data) { $('#listinscore').load(document.url + '#listinscore'); }, beforesend: function(xhr) { alert("enter value"); return $('#txt_updateone').val().trim().length > 0 ? true: false; } error: function (xhr) { alert("error"); } }); return false; } </script>
Comments
Post a Comment