Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.