Radtextbox and jQuery

8 posts, 0 answers
  1. Quim
    Quim avatar
    29 posts
    Member since:
    Nov 2006

    Posted 15 Oct 2009 Link to this post

    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
  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 21 Oct 2009 Link to this post

    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.
  3. Guillaume
    Guillaume avatar
    15 posts
    Member since:
    Sep 2006

    Posted 07 Jan 2010 Link to this post

    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)


  4. Dimo
    Admin
    Dimo avatar
    8482 posts

    Posted 07 Jan 2010 Link to this post

    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.
  5. Guillaume
    Guillaume avatar
    15 posts
    Member since:
    Sep 2006

    Posted 07 Jan 2010 Link to this post

    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
  6. Dimo
    Admin
    Dimo avatar
    8482 posts

    Posted 07 Jan 2010 Link to this post

    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.
  7. Guillaume
    Guillaume avatar
    15 posts
    Member since:
    Sep 2006

    Posted 07 Jan 2010 Link to this post

    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
  8. Dimo
    Admin
    Dimo avatar
    8482 posts

    Posted 07 Jan 2010 Link to this post

    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.
Back to Top