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

[Solved] clientside determine if RadComboBox then get value

3 Answers 256 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 29 May 2008, 07:11 PM
I have a javascript function, confirmExit, that iterates through the controls on the page to see if changes have been made. It compares the values to an Array that contains the initial values. The function works great for text boxes, radio buttons and check boxes. I am trying to enhance it to work for the RadComboBox.

The function is below. I have not been able to change the function so that it detects whether the element is a radComboBox and then gets the VALUE of the radComboBox instead of the TEXT of the radComboBox.


  function confirmExit() {
    if (needToConfirm) {
       // check to see if any changes to the data entry fields have been made
       for (var i = 0; i < values.length; i++)
       {
           var elem = document.getElementById(ids[i]);
           if (elem)
               if ((elem.type == 'checkbox' || elem.type == 'radio')
                       && values[i] != elem.checked)
                   return "You have not saved your changes. Click CANCEL to go back and save your changes,"
               else if (!(elem.type == 'checkbox' || elem.type == 'radio') &&
                       elem.value != values[i])
                   return "You have not saved your changes. Click CANCEL to go back and save your changes,"
           }
           // no changes - return nothing
       }
   }

3 Answers, 1 is accepted

Sort by
0
Rosi
Telerik team
answered on 30 May 2008, 06:23 AM
Hi Paul ,

RadComboBox is rendered as a div element with class=RadComboBox RadComboBox_YourSkinName and id the client id you have set for the RadComboBox control.

The input field of RadComboBox is rendered as input field with className rcbInput and id ClientID of RadComboBox +"_Input". For example: "RadComboBox1_Input".

In your case I suggest you check for the input field.

Also you can read the following article for more details
Client-Side Basics


Regards,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Paul
Top achievements
Rank 1
answered on 30 May 2008, 11:22 PM

Thanks for the reply.  But that answer is over my head. I read Client_Side_Basics also. Here is a simpler question that I think will help resolve my problem:

I have a radcombobox with ID "rcb1". It is bound to a dataset that has two columns. One column is the text shown in the combo box in the browser (DataTextField). The other column contains integers associated with that text (DataValueField). For this example the user selected "Asset" which has an associated value of 1.

I want to get the value, client side. I have tried both of the following, and they both give me the text, "Asset":
...
   var elem = document.getElementById('rcb1_Input');
   return elem.value
...

...
   var elem = document.getElementById('rcb1');
   return elem.value;
...

But I need to get the "1". I also tried
   return elem.get_value;
   return elem.get_value();
But those dont seem to work either.

Here is something else I tried:
    var elem = document.getElementById('rcb1_ClientState');
    return elem.value;

But that returns a long string containing the text AND the value.

I searched telerik.com for _clientstate and it looks like there might be some answers. I will try them and update this post.

0
Rosi
Telerik team
answered on 02 Jun 2008, 07:27 AM
Hi Paul ,

I suggest you try the following code:
<script type=text/javascript>    
function getValue()     
{     
var indexofValue =document.getElementById("rcb1_ClientState").value.indexOf("value");      
var indexofText =document.getElementById("rcb1_ClientState").value.indexOf("text");      
    
alert( document.getElementById("rcb1_ClientState").value.substr(indexofValue+7,indexofText-indexofValue-9));     
}     
</script>    
 




Regards,
Rosi
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
Paul
Top achievements
Rank 1
Answers by
Rosi
Telerik team
Paul
Top achievements
Rank 1
Share this question
or