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

Radcombobox enabled/disabled onload via javascript

14 Answers 805 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Tony Polad
Top achievements
Rank 1
Tony Polad asked on 14 Aug 2008, 07:14 AM
Hi,

I really need to enabled/disabled the RadComboBox via Javascript when the page is load. I need to do it so I can enable / disable the combobox again when the user click another button via JavaScript. I dont want to postback.

I have put the following code in the Page_Init()

ClientScript.RegisterStartupScript(Page.GetType(),

"mykey", "ToggleRadcomboBox();", true);

The javascript is as follow
function ToggleRadcomboBox()
{
    var combo = $find("<%= RadComboBox1.ClientID %>");
    //the combo return null
    combo.set_enabled(false);
    return false;
}

The above code will return me with "null value",
but, when I used:
function ToggleRadcomboBox()
{
    var combo = document.getElementByID("<%= RadComboBox1.ClientID %>");
    // found combo, but unable to do anything
    // combo.set_enabled(false) does not work when using document.getElementByID
    combo.disabled = true;
    return false;
}

Could you please help me out ?

Thanks.

14 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 14 Aug 2008, 07:31 AM
Hello Susanto Siman,

The combobox is null because it is not yet initialized.
You can enable/disable the combobox in the pageLoad() event which is fired when all controls on the page are initialized.

I hope this helps.

Regards,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Tony Polad
Top achievements
Rank 1
answered on 14 Aug 2008, 09:12 AM
Hi,

I did tried to put it on page_load() as well.

None works.

I did tried pageload on javascript as well and it still not working.

Any idea ?

It would be great if you provide me with a very simple sample.

Thanks.
0
Veselin Vasilev
Telerik team
answered on 18 Aug 2008, 03:29 PM
Hi Susanto Siman,

It is too early to find the combobox and set its properties using javascript.

So, what you need to do is just put this code in your aspx page and the combo will be disabled on every page load:

<script type="text/javascript"
function pageLoad() 
    var combo = $find("<%= RadComboBox1.ClientID %>"); 
    combo.disable(); 
</script>  


Sincerely yours,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Chintan
Top achievements
Rank 1
answered on 30 Jul 2011, 09:52 AM
I am trying to get disabled combo box through java script  , its not properly enabled my combo. its not showing dropdwon list while we enabled this control, Below my code
function checkCheckBox() {
    var chk = document.getElementById("ctl00_cph_Main_chkOther");
    if (chk.checked == true) {
        var agree = confirm("Are you sure that you want change the default selection criteria?");
        var TermCode = document.getElementById("ctl00_cph_Main_rcmbTermCode");
        //alert(agree+'   HI');
        if (agree == false) {
            document.getElementById("ctl00_cph_Main_chkOther").checked == false;
            document.getElementById("ctl00_cph_Main_rcmbTermCode").disabled = true;
            return false;
        }
        else {
           document.getElementById("ctl00_cph_Main_rcmbTermCode").disabled = false;
            return true;
        }
    }
    else {
        document.getElementById("ctl00_cph_Main_rcmbTermCode").disabled = true;
    }
}

Please resolve my problem .

0
Thad
Top achievements
Rank 2
answered on 01 Aug 2011, 02:05 AM
Hi Chintan,

Please try this JavaScript code to enable / disable the RadComboBox.

var combo = $find("<%= rcmbTermCode.ClientID %>");
combo.enable(); // to enable the RadComboBox
combo.disable(); // to disable the RadComboBox

You may want to take a look at this page to get more information on how to manipulate the RadComboBox on the client side.
http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcombobox.html

Hope that helps!
Thad
0
Jagz W
Top achievements
Rank 2
answered on 24 Mar 2012, 08:57 AM
Thanks fhis sovled the problem.

Early i was trying like this: $find('<%= rdcomboEduWork.ClientID %>').disable();
0
Sravanthi
Top achievements
Rank 1
answered on 20 Aug 2012, 04:39 PM
combobox.disable() it is erroring out, saying disable() is not a valid function.
ALso, i am doing this onload()

Thanks,
Sri
0
Princy
Top achievements
Rank 2
answered on 21 Aug 2012, 04:27 AM
Hi,

Unfortunately I cannot replicate the issue at my end. Here is the full code that I tried which worked as expected.
aspx:
<telerik:RadComboBox ID="RadComboBox1" runat="server" Height="300px"  OnClientLoad="OnClientLoad">
  <Items>
    <telerik:RadComboBoxItem Text="Fairy Tales" />
    <telerik:RadComboBoxItem Text="Fiction" />
    <telerik:RadComboBoxItem Text="Adventure" />
  </Items>
</telerik:RadComboBox>
JS:
function OnClientLoad(sender, args) {
 $find('<%= RadComboBox1.ClientID %>').disable();
       //or
  sender.disable();
}

Thanks,
Princy.
0
Sravanthi
Top achievements
Rank 1
answered on 21 Aug 2012, 01:54 PM
This is the combobox declaration in aspx ::
<telerik:RadComboBox ID="cmbbranch" runat="server"/>

and the javascript is inside C# code as follows ::

 stringabc.Append("var cmb = document.getElementById(\"" + cmbbranch.ClientID + " \"); if(document.getElementById(\""
                + ddlmethodtype.ClientID + "\").value == \"Customer Pickup\") { cmb.enable() }  else { cmb.disable(); };");

I tried both $find and document.getelementbyid for ::
var cmb = document.getElementById(\"" + cmbbranch.ClientID + " \");

it says either cmb is null or disable() is not a valid function.

Thanks for the help. Aprreciate it.
Sri!!

0
Princy
Top achievements
Rank 2
answered on 22 Aug 2012, 07:27 AM
Hi,

Try disabling the combobox as shown below.
C#:
string script = "function f(){$find(\"" + RadComboBox1.ClientID + "\").disable(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
ScriptManager.RegisterStartupScript(Page, Page.GetType(),
"key", script, true);

Thanks,
Princy.
0
Sumit
Top achievements
Rank 1
answered on 26 Feb 2013, 12:08 PM
Hi,
$find(
'<%= RadComboBox1.ClientID %>').disable();
is not working while RadGrid is in edit mode.

Can use as follows: 

   function OnClientSelectedIndexChanged(sender, eventArgs)
        {
            var clientId = sender.get_id();
            var ddlvalue = document.getElementById(clientId);
            ddlvalue.setAttribute('readOnly', 'readOnly'); // to enable
            ddlvalue.setAttribute('readOnly', ''); // to disable

       }

All the best.

0
Zaher
Top achievements
Rank 1
answered on 14 Oct 2013, 11:34 AM
@ Tony Polad
please try
 
 $(document).ready(function(){
           ToggleRadcomboBox()
        });

function ToggleRadcomboBox()
{
    var combo = $find("<%= RadComboBox1.ClientID %>");
    //the combo return null
    combo.set_enabled(false);
    return false;
}
0
Ramkumar
Top achievements
Rank 1
answered on 05 Dec 2013, 10:42 AM
hi,
 I need radcombobox item to disable except the item which I checked. I am havin no of item in radcombobox. if I check any one item rest all items to be disabled. Can you please help me?
0
Princy
Top achievements
Rank 2
answered on 06 Dec 2013, 11:15 AM
Hi Ramkumar,

Please have a look into the following JavaScript to achieve your scenario.

JavaScript:
<script type="text/javascript">
    function OnClientItemChecked1(sender, args) {
        var count = sender.get_items().get_count();
        if (args.get_item().get_checked() == true) {
            for (var i = 0; i < count; i++) {
                if (sender.get_items().getItem(i).get_checked() == false) {
                    sender.get_items().getItem(i).set_enabled(false);
                }
            }
        }
        else {
            for (var i = 0; i < count; i++) {
                sender.get_items().getItem(i).set_enabled(true);
            }
        }
    }
</script>

Thanks,
Princy.
Tags
ComboBox
Asked by
Tony Polad
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Tony Polad
Top achievements
Rank 1
Chintan
Top achievements
Rank 1
Thad
Top achievements
Rank 2
Jagz W
Top achievements
Rank 2
Sravanthi
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Sumit
Top achievements
Rank 1
Zaher
Top achievements
Rank 1
Ramkumar
Top achievements
Rank 1
Share this question
or