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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need conditional function

Status
Not open for further replies.

Barkley564

Technical User
Nov 27, 2004
14
0
0
US
I've inherited some code that doesn't work properly. There are two functions involved in the problem. The first one calls the second one with this code:

Code:
for (var x = 1; x <= document.all.maxBehavioralID.value; x++)
        ResetRadioSelection(x);
The next function is:

Code:
function ResetRadioSelection(IndexID)
{
    switch(IndexID)
    {
        case 1:
            document.all.radio1[0].disabled=false;
            document.all.radio1[0].checked=false;
            document.all.radio1[1].disabled=false;
            document.all.radio1[1].checked=false;
            break;
        case 2:
            document.all.radio2[0].disabled=false;
            document.all.radio2[0].checked=false;
            document.all.radio2[1].disabled=false;
            document.all.radio2[1].checked=false;
            break;
<snip> repeated to case 20
It works great if the user has all 20 behavioral id's, but some don't, and it will fail on the first one they don't have. I get the is null or not an object error, and any buttons after the place it fails do not reset.

I do have a field that tells me whether a value is used for the person being queried, but I'm not sure how to make that happen. Can you use an if statement in a function? If so, how?

I'm a novice with java so I apologize if I didn't explain this properly.

Any suggestion is appreciated!
 
Reading your code it looks like its just hitting the switch statement and then enabling the radio button and clearing the check box...

It does this based on an UPPER limit set by document.all.maxBehavioralID.value; so if document.all.maxBehavioralID.value; says there are 5 behaviorial id's it will do the first 5, if it says there are 10 it will do the first 10.

There is nothing in your code to asses whether radio1, radio3, radio5 etc should be enabled and cleared while radio2, radio4, radio6 should remain disabled.

Inside your for() loop you would want to include an:
if(somevalue(x) == true)
{
ResetRadioSelection(x);
}

Hope that helps!
 
Can you post your HTML where the radio buttons are being created?

[monkey][snake] <.
 
First off, your code is IE only because it uses document.all.

Try something like this:

Code:
for (var x = 1; x <= document.getElementById('maxBehavioralID').value; x++) ResetRadioSelection(x);

and

Code:
function ResetRadioSelection(IndexID)
{
var relement = document.getElementById('radio' + IndexID);

if (relement)
  {
  relement[0].disabled = false;
  relement[0].checked = false;
  relement[1].disabled = false;
  relement[1].checked = false;
  }
}

This assumes that each radio button array has 2 and only 2 elements. If there are more or less radio buttons in a group, you should use a loop to set .disabled and .checked to false for each group.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top