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

Radtextbox and jQuery

7 Answers 506 Views
Input
This is a migrated thread and some comments may be shown as answers.
Quim
Top achievements
Rank 1
Quim asked on 15 Oct 2009, 05:24 PM
Hi

I'm trying to use jQuery with a Radtextbox, I can read the text but I can't change it
This works fine to read the text:
alert($telerik.$('#RadTextBox1').val())
but this don't:
$telerik.$('#RadTextBox1').val('My text')

How can I change Radtextbox1 text?

Regards

7 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 21 Oct 2009, 10:43 AM
Hello Quim,

The proper JQuery syntax to set or retrieve the RadTextBox value should be as follows:

alert($telerik.$(

'#RadTextBox1_text').val());
$telerik.$(
'#RadTextBox1_text').val('My text')

 

Here is a simple example for further reference:

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
    </Scripts>
</asp:ScriptManager>
<script type="text/javascript">
    function GetSetValue() {
        alert($telerik.$('#RadTextBox1_text').val());
        $telerik.$('#RadTextBox1_text').val('My text')
    }
</script>
<telerik:RadTextBox ID="RadTextBox1" runat="server" />
<input type="button" value="Get/Set textbox value" onclick="GetSetValue()" />

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Guillaume
Top achievements
Rank 1
answered on 07 Jan 2010, 12:05 PM
Just to go further :
I'm trying to set value for all radnumerictextbox contained in a specific div, using Jquery.

I'm currently using this, which works :
$telerik.$(divId + "> .RadInput > .riTextBox").val('');  

I'm just wondering : is  this the best way to do it ?(all the help i can found is based on Id selection, which i don't want to use)


0
Dimo
Telerik team
answered on 07 Jan 2010, 12:19 PM
Hello Guillaume,

The proposed approach will actually not work. It will set/clear the textbox content, which the user sees, but will not modify the actual RadTextBox value and it will be restored on the next textbox focus.

You need to use the ID approach and what's more, you must set the value twice for each RadTextBox instance:

Javascript

// visible textbox, which holds the formatted value
$telerik.$('#RadTextBox1_text').val('My text');

// hidden textbox, which holds the actual value
$telerik.$('#RadTextBox1').val('My text');


Sincerely yours,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Guillaume
Top achievements
Rank 1
answered on 07 Jan 2010, 12:43 PM
Yes, it does not work :(

But I don't want to use the ID approach. I want to be able to reuse my function with only one parameter (the container div id).

So, i just added this line to the previous one, as you shown me :
     $telerik.$(divId + "> .RadInput > .rdfd_").val('');

and it seems to works (till you tell me it does not :) )

now, I just need to be able to enable/disable a textbox on an onclick event on its specific checkbox

Thanks,

Guillaume
0
Dimo
Telerik team
answered on 07 Jan 2010, 01:28 PM
Hello,

Well, you can use that approach if you are happy with it, but note that rdfd_ is an undocumented CSS class used for internal purposes and we don't guarantee that we will not change it in the future (not very likely, but I am notifying you just in case).

Not sure whether your last sentence is a question or not.

Regards,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Guillaume
Top achievements
Rank 1
answered on 07 Jan 2010, 01:42 PM
Thanks for the warning. That's why I was posting here.

I think you should look at so that there's an easier/safer way to select telerik objects with jquery without using id.

As for my my last sentence, it was kind of a question. I have a checkbox which should enable/disable a radnumerictextbox when clicked.

here is my solution (which seems to work)
    function EnableDisableTxt(chkId) { 
        var wrapperId = $("#" + chkId + " ~.RadInput")[0].id; //get the wrapper (first sibling) 
        var txtid = wrapperId.replace("_wrapper", ""); // find the objectid 
        if ($("#" + chkId).is(':checked')) { 
            $find(txtid).enable(); 
        } 
        else { 
            $find(txtid).disable(); 
        } 
    } 

I'm calling this function by : onclick="EnableDisableTxt(this.id);"
(using onclick means that (i believe) i could not use a <%= myradId.ClientId)

Thanks again

Guillaume
0
Dimo
Telerik team
answered on 07 Jan 2010, 01:48 PM
Hello,

As far as I can see, the JS code for enabling/disabling looks OK.

The RadControls' HTML ouput is more complex than the HTML output of the corresponding asp controls, so it is not always possible to allow direct manual manipulation of the RadControls' properties.

Best wishes,
Dimo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Input
Asked by
Quim
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Guillaume
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or