Jump to content

Radio Button Validation ?


ainoy31

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.