This is a migrated thread and some comments may be shown as answers.

Javascript to control checkbox display on Rad button toggle change

3 Answers 232 Views
Button
This is a migrated thread and some comments may be shown as answers.
Rachana
Top achievements
Rank 1
Rachana asked on 07 Feb 2013, 05:46 PM
Hello,

I have the following code on my aspx page

<table width="800px"><tr><td align="right">
        <telerik:RadButton ID="ToggleResponseView" OnCommand="OnToggleResponseView" AccessKey="1" runat="server" ButtonType="StandardButton" ToggleType="CustomToggle">
            <ToggleStates>
                <telerik:RadButtonToggleState Text="SVIEW" />
                <telerik:RadButtonToggleState Text="FRECORD" />
            </ToggleStates>
        </telerik:RadButton>
        </td>
        <td>
        <asp:CheckBox ID="chkisSummary" runat="server" AutoPostBack="true" OnClientToggleStateChanged="chkSummaryAll" OnCheckedChanged="ViewSummaryAll" Checked="false" Visible="true" text="Show All"/>
        </td></tr></table>
  
<script type="text/javascript">
    function chkSummaryAll(sender, args) {
        switch (args.get_currentToggleState().get_text()) {

            case "SVIEW":
                document.getElementById("chkisSummary").checked = false;
                alert("RadButton was clicked.");
                break;}
        }   
</script>


I want to hide the check box 'chkisSummary' when the toggle button ttext is 'SVIEW'. However for somne reason the checkbox object is coming as Null and the javascript does not work.

Please suggest.

3 Answers, 1 is accepted

Sort by
0
Arun
Top achievements
Rank 1
answered on 08 Feb 2013, 12:13 PM
.
0
Princy
Top achievements
Rank 2
answered on 08 Feb 2013, 12:18 PM
Hi Rachana

Try the following aspx and JS to hide checkbox when text is SVIEW.Hope this helps.
aspx:
<table width="800px">
            <tr>
                <td align="right">
                    <telerik:RadButton ID="ToggleResponseView" AccessKey="1" OnClientLoad="OnClientLoad"
                        runat="server" ButtonType="StandardButton" ToggleType="CustomToggle">
                        <ToggleStates>
                            <telerik:RadButtonToggleState Text="SVIEW" />
                            <telerik:RadButtonToggleState Text="FRECORD" />
                        </ToggleStates>
                    </telerik:RadButton>
                </td>
                <td>
                    <asp:CheckBox ID="chkisSummary" runat="server" AutoPostBack="true" Checked="false"
                        Visible="true" Text="Show All" />
                </td>
            </tr>
</table>
JS:
<script type="text/javascript">
function OnClientLoad(sender, args)
{
        var button = $find("ToggleResponseView");
        var text = button.get_selectedToggleState().get_text();
        if (text = "SVIEW")
        {
            var chk = document.getElementById("chkisSummary");
            chk.disabled = true;
        }
    }
</script>

Thanks
Princy.
0
Danail Vasilev
Telerik team
answered on 12 Feb 2013, 11:17 AM
Hi all,

I will make a small correction on the comparison operator in Princy's code:

if (text = "SVIEW")
should be
if (text == "SVIEW")

Greetings,
Danail Vasilev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Button
Asked by
Rachana
Top achievements
Rank 1
Answers by
Arun
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Danail Vasilev
Telerik team
Share this question
or