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
- <script>
- Function to get user
- var user;
- function getUser() {
- var uid = $("#UserId").val();
- $.ajax({
- type: "POST",
- contentType: "application/json; charset=utf-8",
- url: "/Products/getUserById",
- data: JSON.stringify({ UserId: uid }),
- success: onSuccess
- });
- }
- function onSuccess(us) {
- user = JSON.parse(us);
- if (user) {
- $("#FullName").val(user.FullName)
- }
- else {
- user = {};
- $("#FullName").val('')
- }
- }
- Function to get product
- var prod;
- function getProduct() {
- var id = $("#ProductId").val();
- $.ajax({
- type: "POST",
- contentType: "application/json; charset=utf-8",
- url: "/Products/getProductById",
- data: JSON.stringify({ ProductId: id }),
- success: onSuccess
- });
- }
- function onSuccess(res) {
- prod = JSON.parse(res);
- if (prod) {
- $("#ProductName").val(prod.ProductName)
- $("#Description").val(prod.Description)
- $("#Amount").val(prod.Amount)
- }
- else {
- prod = {};
- $("#ProductName").val('')
- $("#Description").val('')
- $("#Amount").val('')
- }
- }
- function SetProduct() {
- var disc = $("#Discount").val();
- var qty = $("#Qty").val();
- var TotalAmount;
- $("#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>')
- }
- </script>