开发者

validation, multiple radio button in each row

I am displaying three radio buttons in each row for each employee, how to validate for empty check.

<td><input type="radio" name="stf_att_<?php echo $stf_id ;?>" value="p" /></td>
<td><input type="radio" name="stf_att_<?php echo $stf_id ;?>" value="a" /></td>
<td><input type="radio" name="st开发者_Python百科f_att_<?php echo $stf_id ;?>" value="l" /></td>

am using another table to display values using id for each employee. have to use name="" for validation but in name am using id from database, how i do with js or php


if(document.getElementById('staff').checked) {
  //will come here is a particular radio is checked

}

You can mark one of the radio buttons as checked (checked="checked") in the HTML code, which would guarantee that one radio button is always selected. Since one of the option is true for all the employees, think this would solve your problem.


Add a class name to each of the three radio buttons like their names. (stf_att_<?php echo $stf_id ;?>). And use the function below to validate radio buttons:

function checkRadio(classname) {
    var el = document.getElementsByClassName(classname);
    for(var i=0; i<el.length; i++) {
        if(el[i].checked) {
            return 1;
        }
    }
    return 0;
}

It is so much easier using a javascript library like jquery.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜