Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input returns true on an empty input

I can't get my head around this issue! I have simple jquery validation on button click to validate if the input field is empty.

http://fiddle.jshell.net/fyxP8/3/

I have no idea why the input filed returns with value not empty when it is empty.

Any help is very much appreciated

like image 805
Khalid Avatar asked Jul 20 '26 08:07

Khalid


2 Answers

see this demo: http://fiddle.jshell.net/Tj7Z8/

extra ; on your if statement

Hope it fits the need :)

code

function checkinputs(ticker, btn) {
    alert(ticker + "[ " + $(btn).parent().find("input").val() + " ]" + $(btn).parent().find("input").val().length);
    var x = false;
    if (ticker == 0) {
        if ($(btn).parent().find("input").val() != '' ) {
            alert($(btn).parent().find("input").attr("name") + "<>" + $(btn).parent().find("input").val());
            x = true;
        }
    }

    return x;
}
var progressTicker = 0;
$("button[class$='nextBtn']").click(function() {
    var returns = checkinputs(progressTicker, this);
    alert(returns);
    if (returns == true) {
        alert('inside');
    }
});​
like image 185
Tats_innit Avatar answered Jul 21 '26 21:07

Tats_innit


I think you just had a typo in your script in this line

    if ($(btn).parent().find("input").val() != '' ); {

The colon is misplaces there... Compare

http://fiddle.jshell.net/fyxP8/10/

like image 25
cljk Avatar answered Jul 21 '26 22:07

cljk