[Solved] if else statement using JAVASCRIPT [closed]


You are comparing the DOM elements (input fields) themselves, not their values. In order to get the values and compare those, you have to actually get the .value property and treat them as Numbers (float or integer or whatever it’s going to be).

function submit() {
    var q = parseFloat(document.getElementById('text1').value);
    var w = parseFloat(document.getElementById('text2').value);

    if (q > w) {
        console.log('q is greater than w');
    }
    else
    {
        console.log('q is less or equal than w');
    }
}
<input type="text" id="text1">
<input type="text" id="text2">
<input type="submit" onclick="submit()">

6

solved if else statement using JAVASCRIPT [closed]