Amir kamal

Amir kamal

  • NA
  • 32
  • 1.7k

Problem in onkeyup event

Feb 3 2020 9:22 AM
looking for help, I have 2 onkeyup events but both are conflicting each other.
 
1.I can populate product detail by entering Product Id , but when i enter the User Id to populate Users name in "Name" field the products field becomes blank and also name of user dont appeares.
 
2.If i comment out get getUser() then getProduct() function fine and vice versa.But both function togeather having issue which i mentioned above.The code and snapshot is attached.
 
 
Please help
  1. <script>  
  2. Function to get user  
  3. var user;  
  4. function getUser() {  
  5. var uid = $("#UserId").val();  
  6. $.ajax({  
  7. type: "POST",  
  8. contentType: "application/json; charset=utf-8",  
  9. url: "/Products/getUserById",  
  10. data: JSON.stringify({ UserId: uid }),  
  11. success: onSuccess  
  12. });  
  13. }  
  14. function onSuccess(us) {  
  15. user = JSON.parse(us);  
  16. if (user) {  
  17. $("#FullName").val(user.FullName)  
  18. }  
  19. else {  
  20. user = {};  
  21. $("#FullName").val('')  
  22. }  
  23. }  
  24. Function to get product  
  25. var prod;  
  26. function getProduct() {  
  27. var id = $("#ProductId").val();  
  28. $.ajax({  
  29. type: "POST",  
  30. contentType: "application/json; charset=utf-8",  
  31. url: "/Products/getProductById",  
  32. data: JSON.stringify({ ProductId: id }),  
  33. success: onSuccess  
  34. });  
  35. }  
  36. function onSuccess(res) {  
  37. prod = JSON.parse(res);  
  38. if (prod) {  
  39. $("#ProductName").val(prod.ProductName)  
  40. $("#Description").val(prod.Description)  
  41. $("#Amount").val(prod.Amount)  
  42. }  
  43. else {  
  44. prod = {};  
  45. $("#ProductName").val('')  
  46. $("#Description").val('')  
  47. $("#Amount").val('')  
  48. }  
  49. }  
  50. function SetProduct() {  
  51. var disc = $("#Discount").val();  
  52. var qty = $("#Qty").val();  
  53. var TotalAmount;  
  54. $("#invoice_body").append('<tr><td>' + prod.ProductName + '</td><td>' + qty + '</td><td>' + prod.Description + '</td><td>' + prod.Amount + '</td><td>' + disc + '</td><td>' + TotalAmount + '</td></tr>')  
  55. }  
  56. </script>  

Answers (4)