ainoy31 Posted August 2, 2007 Share Posted August 2, 2007 I need to validate that a selection has been made upon updating a record. I am using a radio button. Here is the code for the radio button: <td><font face = "Ariel, Helvetica, sans-serif"><input type = "radio" name = "t_id" value = "<? echo $t_id; ?>"></font></td> <td align = "center"><font face = "Ariel, Helvetica, sans-serif"><? echo $fl_num; ?></font></td> <td align = "center"><font face = "Ariel, Helvetica, sans-serif"><? echo $fl_date; ?></font></td> <td align = "center"><font face = "Ariel, Helvetica, sans-serif"><? echo $fl_time; ?></font></td> <td align = "center"><font face = "Ariel, Helvetica, sans-serif"><? echo $de_port; ?></font></td> This is the code I am trying to use and get it to work but no luck. function hasASelection() { var elms = document.getElementsByName(t_id); for(var k=0, elm;elm=elms[k];k++) if(elm.checked) { return true; } return false; } Link to comment https://forums.phpfreaks.com/topic/63066-radio-button-validation/ Share on other sites More sharing options...
mpharo Posted August 2, 2007 Share Posted August 2, 2007 If you wrap it in a <form> you can validate it by checking if $_POST['t_id'] is intialized or not... Link to comment https://forums.phpfreaks.com/topic/63066-radio-button-validation/#findComment-314088 Share on other sites More sharing options...
deadimp Posted August 2, 2007 Share Posted August 2, 2007 Well, this is kind of a PHP forum, but... You need a little more checking around that element, because a text field won't have a variable named 'checked', so that could create problems further down the road. function hasASelection() { var list=document.getElementsByName(t_id); for (k in list) { cur=list[k]; if (cur.tagName=="INPUT" && cur.type=="radio" && cur.checked) return true; } return false; } Though, I'm not sure what entirely this acheives, since by default you should have one radio enabled. By the looks of it, you only have one. Link to comment https://forums.phpfreaks.com/topic/63066-radio-button-validation/#findComment-314096 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.