本文介绍了验证textbox1值是否大于textbox2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮帮我...



i有2个文本框..



Textbox lastprice = 100

Textbox harga = 101



i想验证文本框harga ...



我的尝试:



Help me please...

i have 2 textbox..

Textbox lastprice = 100
Textbox harga = 101

i want validation textbox harga...

What I have tried:

<div class="form-group">
                <label> Harga Barang Terakhir Dibeli per satuan</label>
                <input type="text" name="lastprice" class="form-control" value="<?= __nama('tb_barang', 'id_barang', $row->id_barang, 'harga'); ?>" disabled="disabled">
            </div>

            <div class="form-group">
                <label> Harga Barang per satuan</label>
                <input type="text" name="harga" class="form-control" onkeypress="return isNumberKey(event)" placeholder="Input harga barang" autofocus="autofocus" required="required"/>
            </div>







<script>
function checkPrice(){
        var lastprice = document.getElementById('lastprice').value;
        var harga = document.getElementById('harga').value;
        if(harga.val > lastprice.val){
             alert("entered value is bigger");
             return false;
           }
         }
</script>

推荐答案







<script>
function checkPrice(){
        var lastprice = document.getElementById('lastprice').value;
        var harga = document.getElementById('harga').value;
        if(harga.val > lastprice.val){
             alert("entered value is bigger");
             return false;
           }
         }
</script>


function checkPrice(){
    var lastprice = parseFloat(document.getElementById('lastprice').value);
    var harga = parseFloat(document.getElementById('harga').value);

    if (isNaN(lastprice) || isNaN(harga)) {
        alert("Entered values are not numeric.");
        return false;
    }

    if (harga > lastprice) {
        alert("Entered value is bigger");
        return false;
    }

    return true;
}



这篇关于验证textbox1值是否大于textbox2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 14:33
查看更多