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

Problem on enable a control in javascript

Status
Not open for further replies.

josemauricio

Programmer
Joined
Sep 2, 2003
Messages
65
Location
BR
Hello people.

I have two radiobuttonlist, which one depends on the other. If I click in a option of the first radiobuttonlist, the other radiobuttonlist must be disabled and vice versa. Ok, sometimes, this components is shown already checked, based on information in my database. So, if the second option of the first radiobuttonlist is shown checked, the second radiobuttonlist must be disabled. I have a javascript function that changes the disabled property of the second radiobuttonlist when the user changes the selected option of the first. The problem is that when I disable the second radiobuttonlist at runtime when the page is loading, the javascript function just doesn't work. Anybody knows why is it happening and a solution for this?

I'm almost becoming nuts with it!!!!!

Thanx for any help.

José Maurício.
 
José - someone may have a ready solution, but in the meantime if you could post some code (e.g., where in the load process you are calling the java function), just enough to test on this end.
 
Ok Isadore, here is the code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

rdoTipo.Attributes.Add("onclick", "rdoTipo_onclick()") 'sets the function rdoTipo_onclick to the onclick event of the rdoTipo radiobuttonlist

rdoTipo.SelectedValue = usuPerm.Tipo 'usuPerm is a class that I created and Tipo is a property of this class wich value is attributed with the value of its respective table field on my data base

If rdoTipo.SelectedValue <> "M" Then
rdoSexo.enable = False
End If
end Sub

Now, the function written in javascript that I've created to execute when the user clicks on rdoTipo:

function rdoTipo_onclick()
{
if (frmCadastro.rdoTipo[0].checked)
{
frmCadastro.rdoSexo[0].disabled = false;
frmCadastro.rdoSexo[1].disabled = false;
}
else
{
frmCadastro.rdoSexo[0].disabled = true;
frmCadastro.rdoSexo[1].disabled = true;
}
}

My problem is, when I set the rdoSexo enable property to false in load event of the page, the javascript function doesn't work. Otherwise, it works fine. What's the problem.

Thanx.
 
Jose - ended up being a bit hamstrung today; in between laptops and found myself on a desktop incapable of running dot NET, so couldn't test!

Couple of things I can mention, may or may not be related to the ultimate solution; but hopefully someone will drop by and add their 2 cents.

I probably would have created two checkboxes with independent names, and a common Group Name, e.g.,

Code:
..load event set checked condition:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then
...
rdoSexo.Attributes.Add("onclick", "rdoTipo_onclick()")
rdoSexo2.Attributes.Add("onclick", "rdoTipo_onclick()")
rdoTipo.SelectedValue = usuPerm.Tipo 

If rdoTipo.SelectedValue <> "M" Then
 rdoSexo.enable = False
 rdoSexo2.enabled = True
 rdoSexo2.checked = True
Else
 rdoSexo.checked = True
 rdoSexo2.enabled = False                  
End If
End If
end Sub
...
<html>
...
<asp:Radiobutton id="rdoSexo" runat="server" GroupName="catA"/>
<asp:Radiobutton id="rdoSexo2" runat="server" GroupName="catA"/>
...
</html>

..the java function looking like:
function rdoTipo_onclick()
{
  if (frmCadastro.rdoTipo[0].checked)
  {
    frmCadastro.rdoSexo[0].disabled = false;
    frmCadastro.rdoSexo2[1].disabled = true;
  }
  else 
  {
    frmCadastro.rdoSexo[0].disabled = true;
    frmCadastro.rdoSexo2[1].disabled = false;
  }
}

A two object approach, the javascript syntax might vary. Anyway Jose my first thought was that I was going to have a chance to test this today and it didn't happen, so a couple of thoughts here.

Your post might be one element off - so could be very close as is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top