开发者

Searching if a check boxes value contains something with javascript on PHP

So im trying to check all the checkboxes in my form in which values contain "United Kingdom" (this value does change)

at the moment ive tried开发者_如何学编程 creating a function based on some google snippets but no luck, here it is:

function checkValue(field, value) {
    for (i = 0; i < field.length; i++)
    if (field.indexOf(value) != -1) {
        field[i].checked = true;
    }
}

and i call it with a button like this

OnClick="checkValue(document.form.vote, document.form.countrylist.value)"

its pulling the data from a listbox if that helps

Thanks, Ben


Try this instead:

function checkValue(field, value) {
    for (i = 0; i < field.length; i++) {
        if (field[i].value.indexOf(value) != -1) {
            field[i].checked = true;
        }
    }
} 


Could the issue be this?

field[i].checked = 'checked'

instead of true? As far as I know 'checked' is the value for the attribute 'checked'. If this is a dumb answer sorry, I haven't done DOM stuff without jQuery in forever.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜