我正在使用希望以美分输出数量的付款系统。提交表单字段时提交
为了避免混淆,我希望我的客户能够输入十进制的数字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