我想要做一個function
通過handle
方法的textbox("@Html.TextBox("ItemID")")
用戶的輸入,自動在數據庫中獲取物品的價格。如何在JavaScript中編寫SQL函數?
//SalesSub.cs
public class SalesSub
{
public string ItemID { get; set; }
public int Qty { get; set; }
public decimal UnitPrice { get; set; }
}
//Create.cshtml
<script type="text/javascript">
function handle(e) {
//Detect when the user press 'Enter' Or 'Tab' Key
var keyCode = e.keyCode || e.which;
if (keyCode === 13 || keyCode == 9) {
var itemID = $('#ItemID').val()
//Get the item ID in the textbox value,
//so how to search the price of the
//item in database? Using SQL or Others?
$('#UnitPrice').val() = //Result After Search
}
return false;
}
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
</script>
<label>Item ID :</label>
**@Html.TextBox("ItemID", string.Empty, new { onkeydown = "handle(event)" })**
<label>Qty :</label>
@Html.TextBox("Qty")
<label>Sales Price :</label>
@Html.TextBox("UnitPrice")
}
我想你的帖子可能已收到dowvotes,因爲它不清楚問題是什麼。你能詳細說明嗎? – fjdumont
是的,首先我要允許用戶在「ItemID」文本框中鍵入項目ID,而在用戶完成後輸入項目ID並在鍵盤上按下「Enter」或「Tab」鍵,然後函數handle()可以自動獲取物品的價格。所以,我的問題是如何獲得物品的價格?它使用SQL嗎?那麼我如何在JavaScript中編寫SQL? –