开发者

function to validate text box on blank or default text

function checkForm(f) {
    if (f.elements['zoom_query'].value == "" || "Search - Movie or Actor") {
        f.zoom_query.focus();
        return false;
    } else {
        f.submit();开发者_运维百科
        return false;
    }
}

this prevents form submission for any string

any idea?


I think it should read:

(f.elements['zoom_query'].value == "" || f.elements['zoom_query'].value == "Search - Movie or Actor")

Otherwise it always evaluates true


If you can use jQuery I'd recommend having a look here: http://docs.jquery.com/Plugins/validation

And this question contains an answer that solves the problem you're having using jQuery Form Validation.


function checkForm(f) {

    if (f.zoom_query.value == "" || f.zoom_query.value == "Search - Movie or Actor") {
        alert("Please fill in the text field.");
        f.zoom_query.focus();
        return (false);
    }

    f.submit();
    return (true);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜