javascript - 我想当余额 >0 时,表单不会在 php 中提交?

标签 javascript php

我想要,如果余额字段为<0,如果充值金额提交>0,则表单无法提交,您能给我Java脚本或PHP代码吗?这是我的编辑代码,但不起作用,我不明白。请给我解决方案

<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

<script type="text/javascript"> 

form.onsubmit = function(e){  
    if(document.getElementById("bal").value==30){
         e.preventDefault();
       alert("Value must not be equal to 30"); 
    }
    if(document.getElementById("bal").value<0){
         e.preventDefault();
       alert("error msg");
       return false; 
    }
    if(document.getElementById("amount").value>0){
         e.preventDefault();
       alert("error msg");
       return false; 
    }
};

</script>


</head>
<body>
<form action = '' method='post' name="recharge">
<input type="text" id="bal" name="bal" value="">Balance</><br>
<input type="text" id=="number" name="number" value="">Rehcarge number</><br>
<input type="text" id="amount" name="amount" value="">Amount</><br>
<input type="submit" name="submit" value="SUBMIT">
</form>

</body>
</html>

最佳答案

尝试:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

<script type="text/javascript"> 

jQuery(document).ready(function($) { 

   jQuery("input[name='button']").click(function(e){

        //getting your balance amount
        bal = jQuery("input[name='balance']").val();

        //if balance is lesser than 0, form will be submitted
        if(bal<0){
         jQuery('form').submit();
       }
   });

});

</script>

确保您的输入字段包含在 <form></form> 内标签。

关于javascript - 我想当余额 >0 时,表单不会在 php 中提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22167556/

相关文章:

javascript - 模块解析失败 : Unexpected token - react-refresh-webpack-plugin/loader

javascript - 基本 For 循环逻辑对我来说没有意义

php - 损坏的 CSS Sprite

php - 如何将表单数据提交到MySQL数据库

php - 在php中将指数数转换为小数

php - 用于超大列表的 Web 编程语言?

javascript - 使用 JavaScript 调用 Shell 脚本实现自动化

javascript - Jquery头标签问题

javascript - 如何在元素移动时移除悬停状态

php - AspectMock 似乎没有模拟静态方法