Run Javascript Onblur of textbox

4 posts, 1 answers
  1. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 13 Aug 2009 Link to this post

    I have four radtextboxes. On the fourth one, I want to call a JavaScript function. I need to get all four of the values of the textboxes to manipulate them. So far, I cannot get anything to fire on my onblur event. Anyone know why? Here is my code.

    <%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/admin/Admin.Master"
        CodeBehind="AddBusiness.aspx.vb" Inherits="ClickableCommunity.AddBusiness" %>

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
        <script type="text/javascript">
            function getLatLon(street, city, state, zip) {
                alert(street + city + state + zip);
            }//getLatLong
            
        </script>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="header" runat="server">
    </asp:Content>
    <asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
        <telerik:RadTextBox ID="streetInput" runat="server" Label="Street">
        </telerik:RadTextBox>
        <telerik:RadTextBox ID="cityInput" runat="server" label="City">
        </telerik:RadTextBox>
        <telerik:RadTextBox ID="stateInput" runat="server" label="State">
        </telerik:RadTextBox>
        <telerik:RadTextBox ID="zipInput" runat="server">
            <ClientEvents OnBlur="getLatLon('<%= streetInput.ClientID %>',
                                            '<%= cityInput.ClientID %>',
                                            '<%= stateInput.ClientID %>',
                                            '<%= zipInput.ClientID %>')" />
        </telerik:RadTextBox>
    </asp:Content>

  2. Answer
    Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 14 Aug 2009 Link to this post

    Hello,

    Try the following approach:

        <telerik:RadTextBox ID="streetInput" runat="server" Label="Street">  
        </telerik:RadTextBox> 
        <telerik:RadTextBox ID="cityInput" runat="server" Label="City">  
        </telerik:RadTextBox> 
        <telerik:RadTextBox ID="stateInput" runat="server" Label="State">  
        </telerik:RadTextBox>      
          
        <telerik:RadScriptBlock ID="ScriptBlock1" runat="server">      
            <script type="text/javascript">          
                function getLatLon(sender, args)  
                {                      
                    var streetInput = $find('<%= streetInput.ClientID %>');  
                    var cityInput = $find('<%= cityInput.ClientID %>');  
                    var stateInput = $find('<%= stateInput.ClientID %>');  
                    var zipInput = $find('<%= zipInput.ClientID %>');              
                }          
            </script>      
        </telerik:RadScriptBlock> 
          
        <telerik:RadTextBox ID="zipInput" runat="server">  
            <ClientEvents OnBlur="getLatLon" /> 
        </telerik:RadTextBox> 

    I hope this helps.

    Regards,
    Tsvetoslav
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Web Services
    Web Services avatar
    243 posts
    Member since:
    Apr 2008

    Posted 14 Aug 2009 Link to this post

    Thanks for the reply I will check it out. I have noticed $find $get etc. Are those some built in functions for the rad controls or something? If so, is there some documentation on them somewhere. It kind of confused me when I saw them first. especially coming from PHP.
  5. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 14 Aug 2009 Link to this post

    Hi there,

    $get can be used as shorthand for the document.getElementById and element.getElementById functions.  The $get shortcut function points to the Sys.UI.DomElement.getElementById JavaScript function which is defined as part of the ASP.NET AJAX client side library (which means you will need to include a ScriptManager on the page to be able to use it).  $get accepts two parameters, the first is the ID of the DOM element you want to retrieve, the second is the parent element of where the search starts.  The second parameter is optional and when it is not supplied defaults to the document element.  Here is the official API reference.

    The $find shortcut function allows you to look up an ASP.NET AJAX client side Component by it's ID.  Here is a link to the $find shortcut's documentation and below is the API description.

    All the best,
    Paul
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top