Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onClick event handler 1

Status
Not open for further replies.

FederalProgrammer

Programmer
Jul 2, 2003
318
CA
I have 3 types of Accounts and for each of them different count of radio buttons should be displayed:
Code:
Silver = 1 radio button should be displayed
Gold = 2 radio buttons should be displayed
Platinum = 3 radio buttons should be displayed

I display the radio buttons and assign an onclick event handler in php using the following code:
Code:
for ($i = 0;$i < count($rooms); $i++)
{
   $result = mysql_query("SELECT * FROM rooms WHERE id={$rooms[$i]}");
   $row = mysql_fetch_object($result);
					
   $roomNum = $rooms[$i];
   echo "<input type='radio' 
                name='rdiChat' 
                value='$roomNum' 
                onclick = HandleChatroomSelected();> 
                $row->name
         </a>";
}

and here's the definition of the HandleChatroomSelected()
Code:
function  HandleChatroomSelected()
{
   var selectedChat = 'Donot know yet';

   // in here, document.form.rdiChat is undefined, when there is only a single radio button
   //but it works when I have more than 1 radio buttons on document.form	
   
   for (i = 0; i < document.form.rdiChat.length; i++)
   {
      if (document.form.rdiChat[i].checked)
      {
         selectedChat = document.form.rdiChat[i].value;
      }
   }
   //...more code in here ...
}


---------------
 
Try:

Code:
[b]if(!document.form.rdiChat.length || document.form.rdiChat.length == 1)
{
 selectedChat = document.form.rdiChat.value;
}//end if
else
{
[/b]
 for (i = 0; i < document.form.rdiChat.length; i++)
   {
      if (document.form.rdiChat[i].checked)
      {
         selectedChat = document.form.rdiChat[i].value;
      }
   }
[b]}//end else[/b]

It's likely that if there is only one radio button, then it is not referenced by rdiChat[0], but just by rdiChat (i.e., no index).

'hope that helps.

--Dave
 
'glad to be of help. I left out a tiny bit of code. I'm sure you caught it, but here it is anyway:

Code:
if(!document.form.rdiChat.length || document.form.rdiChat.length == 1)
{
 [b]if (document.form.rdiChat.checked)
 {[/b]
  selectedChat = document.form.rdiChat.value;
 [b]}//end if[/b]
}//end if
...

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top