检查可变总成本的最小值,如果小于最小值,则显示警报消息

Check minimum value of a variable total cost and display alert message if less than minimum value

本文关键字:最小值 显示 消息 小于 如果 总成本 检查      更新时间:2023-09-26

嗨,如果总成本低于 50.00 英镑,我正在尝试限制用户在购物车上结账,而是显示 javascript 警报消息。

我是javascript的业余爱好者。

任何建议或帮助将不胜感激。

提前谢谢。

下面是示例代码:

<form action="Checkout.asp" method="post" name="Form1" onSubmit="return ValidData()">
<span id=total>{total}</span>
</form>

Javascript:

function handlingcharge()
{
document.getElementById('total').innerHTML = '{CurrencySymbol}' + (dblTaxCost + (dblCostOfItems + dblFreight + dblHandling)).toFixed(2);
}
function ValidData()
{
if(document.Form1.total)
{
    if(document.Form1.total.value < 50)
    {
        alert('minimum order value is £50');
        document.Form1.total.focus();
        return false;
    }
}
if (!validateBudget()) return false;
if (!hasApproverEmail()) return false;
EnableFields();
if (!AgreedTerms()) return false;
return true;
}
funcation Validate()
{
   if(parseInt(document.getElementById('Total').innerHTML) <50)
   {
       alert('Your message');
       return false
   }
   return true;
}

这应该可以解决问题。但是,我建议在服务器端进行验证,因为客户端容易受到攻击并且很容易通过。祝你好运!

function validateTotal()
 {
   var totalValue = parseInt($("span[id=total]").text());
   if(totalValue < 50)
     {
        return true;
     }   
  }

用法:

 if(validateTotal())
 {
    alert('Less than 50 dollars');
 }