开发者

function to validate text box on blank or default text

开发者 https://www.devze.com 2023-02-19 09:49 出处:网络
function checkForm(f) { if (f.elements[\'zoom_query\'].value == \"\" || \"Search - Movie or Actor\") {
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

精彩评论

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