Gets the value of a querystring with Javascript

by ebarcza 8/23/2012 12:37:00 PM
   1:  // Gets the value of a querystring key
   2:              function GetQuerystring(ji) {
   3:                  //debugger;
   4:                  hu = window.location.search.substring(1);
   5:                  gy = hu.split("&");
   6:                  for (i = 0; i < gy.length; i++) {
   7:                      ft = gy[i].split("=");
   8:                      if (ft[0] == ji) {
   9:                          return ft[1];
  10:                      }
  11:                  }
  12:              }

Tags:

JavaScript

ASP.NET Button Click on enter keypress with Javascript and Telerik radcombobox

by pencilvac 4/24/2012 5:18:00 AM

In most modern web browsers if you have focus in a text box and press the enter key it will submit your form for you. I came across a situation where I wanted my aspx page to postback after a user makes a selection in a telerik radcombobox and then presses the enter key. Normally this does not happen automatically like a regular text box so I need a solution:

SOLUTION: In my radcombobox I used the client side event OnClientKeyPressing:

<telerik:RadComboBox OnClientKeyPressing="CheckPressEnterKey" ID="rcbCounterParties"  runat="server"></telerik:RadComboBox>

This client side event is wired up to the javascript function specified which accepts two arguments sender and args, as is seen below:You can access which key the user pressed in the args argument. The enter key has a keyCode of 13 so with a simple if statement we can test the key, if it is indeed the enter key then we can manually click the button we want. Its that easy.


                function CheckPressEnterKey(sender, args) {

                    if (args._domEvent.keyCode == 13) {
                        document.getElementById('<%=btnLoad.ClientID  %>').click();
                    }
                }

Note: You will obviously need to put the javascript function within a telerik radcodeblock in order access the buttons client ID as shown.

Tags:

.NET | ASP.NET Enterprise Library | JavaScript | Telerik

Disable Asp.net form validators with Javascript API

by pencilvac 2/17/2012 12:00:00 PM

You may come across the necessity in a project to disable or enable server side asp.net form validators because of some form of client side action with javascript. In my scenario I had to either display or hide a state dropdownlist ( a telerik control radcombobox) and show a region/province text box in a customer input form depending on whether the user was from the USA or another country. When the user was outside of the U.S. we obviously need to remove the state recquired field validator.

In order to do so I took advantage of the very robust Telerik radcombobox javascript api which included the onClientLoad and OnClientSelectedIndexChanged Client side functions which I attached to my countries radcombobox.

<telerik:RadComboBox  Width="142" ID="ddlCountries" OnClientLoad="checkCountry" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged"  runat="server" MarkFirstMatch="True" />

onClientLoad runs any javascript you put inside of it immediately after the drop down is done loading. OnClientSelectedIndexChanged runs, well, right after the user picks a new value in the drop down.

OnClientLoad function :

    function checkCountry(sender) {

        var value = document.getElementById('<%=ddlCountries.ClientID  %>').value;

        if (value !== "United States") {

            var stateValidator = document.getElementById('<%= valState.ClientID  %>');
            ValidatorEnable(stateValidator, false);

        }
        else {

            var stateValidator = document.getElementById('<%= vaState.ClientID  %>');
            ValidatorEnable(stateValidator, true);

        }
    }

Basically the function onload checks to see if the value of the drop down selected is the United States or not. If it is the U.S. then the 

ValidatorEnable function take the parameter of the server ID of the validator you either want to enable or disable as well as whether you want

to enable or disable it. In order to retrieve the Client side ID of the validator I threw the javascript functions within a Telerik Code block.

 

Like magic you can disable and/or enable your asp.net server side validators from client side javascript using the Telerik javascript API.

Tags:

ASP.NET AJAX | JavaScript | Telerik

Get the Selected Radiobutton from Radio Button List in Javascript

by ebarcza 8/20/2010 11:56:00 AM

Just pass in the clientid of the Radio button list control and this function will return the ID of the selected radio button so you can do what you want with it.

function GetRBLSelectionID(RadioButtonListID) {
    var RB1 = document.getElementById(RadioButtonListID);
    var radio = RB1.getElementsByTagName("input");
    var isChecked = false;
    var retVal = "";
    for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked) {
            retVal = radio[i].id;
            break;
        }
    }
    return retVal;
}

 

 

Tags: , ,

.NET | JavaScript

Handle Enter key like the Tab key

by jrose 5/7/2010 9:57:00 AM

To allow ease of use for users that aren't accustomed to using the Tab key to switch between HTML elements and would prefer to use the Enter instead, simply add a OnKeyDown event handler to the element that changes a key code of 13 [Enter's value] to 9 [Tab's value].

 

For example:

<input type="text" onkeydown="if (event.keyCode==13) {event.keyCode=9; return event.keyCode }" id="text1">

<input type="text" id="text2">

 

After entering text into the text1 element, the user is allowed to press Enter [or Tab] to navigate to the text2 element.

Tags: , , , , , ,

JavaScript

Javascript switch statement

by ebarcza 10/13/2009 10:26:00 AM

Skeleton switch statement 

switch(i)
{
case 1:
  do code 1
  break;
case 2:
  do code 2
  break;
default:
 default code

}

Tags:

JavaScript

How to access popup parent window elements with JavaScript

by ebarcza 10/8/2009 10:28:00 AM
How to access popup parent window elements with JavaScript

The JavaScript code to access parent windows elements is not a complex one. Indeed, all that is needed is the code window.opener. The rest of the element can be addressed as per usual.

If you wanted to submit a form in the parent window for example, the following code would be used:

window.opener.document.myForm1.submit();

As mentioned the code window.opener will access the parent window and document.myForm1 will point to your form (in this case called myForm1) within the document, and then with the function submit(), the information from the form is sent.

Tags: ,

JavaScript

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  September 2017  >>
MoTuWeThFrSaSu
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

View posts in large calendar

Recent comments

Tags

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017

Sign in