简体   繁体   中英

onselectedindexchanged() not being called and confirm box clears text even when cancel button is clicked

I am trying to clear the content of the RadEdiotors when different item is selected from the drop down list. The following script does clear the editors' content when OK is clicked but it also clears the content when even cancle button is clicked in the Confirm box that shows up. What is wrong with the following script? Also, in code behind, the onselectedindexchanged() event of this dropdown is also not being called when a different item is selecetd from the list. How do I make it work? Please help.Thanks.

<script type="text/javascript">

        var showConfirm = 1; 

   function onClientSelectedIndexChanging(item) {
    var editor1 = $find("<%= Editor1.ClientID %>");
    var editor2 = $find("<%= Editor2.ClientID %>");
    var content= editor.get_html();  
    var callBackFn = function (arg) 
    { 
        if (arg == true && showConfirm == 1) 
        { 
            var combo = item.ComboBox; 
            combo.ClearSelection(); 

            showConfirm = 0; 

            combo.FindItemByText(item.Text).Select(); 
            combo.SetText(item.Text); 

            __doPostBack("cboxLanguage", '{\"Command\":\"Select\"}'); 

            showConfirm = 1;             
        } 
    }


    if (showConfirm == 1 && content != '') 
    {

        confirm('Changing the language will clear the content of the ediotrs. Click OK to proceed.', callBackFn);

        alert(confirm);
         if (content != null) 

         {
                 editor1.set_html("");
                 editor2.set_html("");
                 return true
          }
          else 
          {
              return false;
          } 
    } 
    return false; 
} 
</script> 

Its telerik's Radcombobox that I am using and RadEditor.

This is my combobox :-

   <telerik:RadComboBox ID="cboxLanguage" TabIndex="2" runat="server" AutoPostBack="false" OnSelectedIndexChanged="cboxLanguage_OnSelectedIndexChanged" OnClientSelectedIndexChanging="onClientSelectedIndexChanging">
</telerik:RadComboBox> 

I want if confirm==true then clear editors' content otherwise not. How do I get the "true" value of this confirm box? Also, how do I get the OnSelectedIndexChanged() event to be called?

Can anyone please help? What am I doing wrong here?

edit alert(confirm); returns the complete function code. How do I fetch the true/false values and clear editors' content based on that?

Try replacing your confirm statement with this:

 var c = confirm('Changing the language will clear the content of the ediotrs. Click OK to proceed.', callBackFn);

Doing that will assign the result of the confirm function to the variable called 'c' and you can use that variable as a boolean.

Also, instead of alert(confirm); you would do alert(c);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM