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

how to send data into function using onclientselectedindexchanged

5 Answers 173 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 16 Jun 2016, 08:08 PM
oComboBox.OnClientSelectedIndexChanged = "ShowHideTextbox('" & oComboBox.ClientID & "','" & oTextbox.ClientID & "','" & oLabel.ClientID & "')"

^ doesn't work and I see on API I should just have a function name there such as this?
oComboBox.OnClientSelectedIndexChanged = "ShowHideTextbox"

inside my js function I see I can do this
 var item = eventArgs.get_item();

but how can I assign my 3 values into arguments called into the function?

5 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 17 Jun 2016, 11:24 AM
Hello Doug,

Here's how you can send additional data as parameters and access the data in the ComboBox' OnClientSelectedIndexChanged client-side event handler:
protected void Page_Load(object sender, EventArgs e)
{
    string myParameter1 = "Value1";
    string myParameter2 = "Value2";
    string myParameter3 = "Value3";
    oComboBox.OnClientSelectedIndexChanged = "function(sender, args){ShowHideTextbox(sender, args, '" + myParameter1 + "'" + ", '" + myParameter2 + "'" + ", '" + myParameter3 + "');}";
}

function ShowHideTextbox(sender, args, param1, param2, param3) {
    // access param1, 2, 3...
}


Regards,
Ivan Danchev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Doug
Top achievements
Rank 1
answered on 17 Jun 2016, 02:39 PM
I used the wrong caller as I am using checkboxes so I changed it to .OnClientItemChecked
0
Doug
Top achievements
Rank 1
answered on 17 Jun 2016, 04:34 PM
I can only get this to half work.
I have to iterate through checkboxes, find "Other" one and see if it is checked and then show / hide an input.

I searched your sample code to loop the combobox checkboxes and could not get any of the functions to work. but it may also be the same issue that I did get working.
anyhow here is the code that works when called on page load (not from the combobox itself) to init my hide/show. <-- this code works

function ShowHideTextbox(sender, args, oDropID, oTextID, oLabelID) {
 
    //var ddl = document.getElementById(oDropID);
 
    var oTextbox = document.getElementById(oTextID);
    var oLabel = document.getElementById(oLabelID);
    var bShow = false;
 
    $('#' + oDropID + ' INPUT').each(function () {
       // alert(this);
        if (this.type == "checkbox") {
            if (this.checked) {
                var sText = this.nextSibling.data;
                if (sText == "Other") bShow = true;
            }
        }
    });
    if (bShow) {
        oLabel.style.display = 'inline';
        oTextbox.style.display = 'inline';
        oTextbox.focus();
    } else {
        oLabel.style.display = 'none';
        oTextbox.style.display = 'none';
    }
}

 

but when this is called from the combobox using the .OnClientItemChecked there are only 2 items in this loop (text + hidden)

it is like the div isn't built out yet. is it calling it too soon to loop the items?

I have verified both calling from page load and combobox sends in the same values.

0
Doug
Top achievements
Rank 1
answered on 17 Jun 2016, 07:54 PM
ok I search the page source and see the div name that has my checkboxes added _DropDown to the name so I changed it to
$('#' + oDropID + '_DropDown INPUT').each(function () {

^ this works for me
0
Ivan Danchev
Telerik team
answered on 20 Jun 2016, 10:36 AM
Hello Doug,

I am glad passing additional data to the OnClientItemChecked handler worked as expected and you were able to access the checkboxes with the modified selector.

Regards,
Ivan Danchev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
ComboBox
Asked by
Doug
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Doug
Top achievements
Rank 1
Share this question
or