How to use comparison operator in Javascript for two input values

后端 未结 4 1505
梦如初夏
梦如初夏 2021-01-27 04:01

I want to compare the two input values, just try in javascript, but it\'s not working fine. I\'m using the following code

function check_closing()
{
var opening         


        
4条回答
  •  执念已碎
    2021-01-27 04:36

    First of all you you need to convert the strings into integers

    function check_closing(){
        var opening = parseInt($('#opening').val(), 10);
        var closing = parseInt($('#closing').val(), 10);
        if(opening > closing){
            alert('Opening is greater than Closing. Please enter the correct value');
            $('#closing').val('');
        }
    }
    

提交回复
热议问题