我正在使用希望以美分輸出數量的付款系統。提交表單字段時提交
爲了避免混淆,我希望我的客戶能夠輸入十進制的數字123.45而不是12345。我如何更換提交期限以便格式正確?我試圖實現onclick JavaScript,但似乎沒有得到th語法或定位權。
的形式,因爲是在這裏:
<form action="https:/….Default.aspx" method="post">
<table> <tbody>
<tr>
<td>Client Reference:</td>
<td><input name="orderid" type="text" value=" " /></td>
<td>e.g. Smith 2017</td>
</tr>
<tr>
<td>Amount in euros:</td> \<td><input name="amount" type="text" value=" " /></td>
<td>please put the amount in cents instead of using full stop (.) e.g. 12356 instead of 123.56</td>
</tr>
<tr>
<td><input type="submit" value="Pay" /></td>
<td></td>
</tr>
</tbody>
</table>
<input name="currency" type="hidden" value="EUR" />
<input name="windowstate" type="hidden" value="3" />
<input name="merchantnumber" type="hidden" value=「/>
</form>
我一直在玩的JavaScript是
onsubmit = 「removeperiod()」
<script type = "text/javascript">
function removeperiod() {
var str = 「amountenter」
str = str.replace(/./,」」);
amountenter = str; // write the de-accented string back into the form field.
}
</script>
任何幫助非常讚賞。
爲什麼不在後端將他們輸入的數量除以0.01? –
強烈建議在服務器端執行此操作,因爲您的客戶端可能會關閉javascript。除此之外,你需要避開這段時間。 '替換(/\./,「」)' –
你所需要做的只是100的倍數。 – nerdlyist