Snipplrhttp://snipplr.com/language/javascript/tags/variable
Recent snippets posted on Snipplr.comen-usSat, 10 Dec 2016 02:48:14 GMT(JavaScript) Reading GET variables in Javascript - gromitskihttp://snipplr.com/view/72940/reading-get-variables-in-javascript/
Function enables the reading of url appended variables. See URL for more information. ]]>Tue, 19 Nov 2013 20:02:25 GMThttp://snipplr.com/view/72940/reading-get-variables-in-javascript/(JavaScript) sharepoint absolute site collection URL javascript variable - rumremixhttp://snipplr.com/view/71802/sharepoint-absolute-site-collection-url-javascript-variable/
Works in SP2013 (and I believe 2010). Provides site collection URL without trailing "/" ]]>Thu, 11 Jul 2013 04:55:00 GMThttp://snipplr.com/view/71802/sharepoint-absolute-site-collection-url-javascript-variable/(JavaScript) Javascript revealing module pattern template - coprolithttp://snipplr.com/view/50765/javascript-revealing-module-pattern-template/
"Javascript module pattern emulates the concept of classes in such a way that we're able to include both public/private methods and variables inside a single object, thus shielding/namespacing particular parts from the global scope."
When inheritance is not needed and a only few instances is needed (Keep in mind that each instance places a new copy of each function in memory!) ]]>Thu, 17 Mar 2011 08:40:45 GMThttp://snipplr.com/view/50765/javascript-revealing-module-pattern-template/(JavaScript) Variable-sized Image Map, version 0.01 - xtknighthttp://snipplr.com/view/36398/variablesized-image-map-version-001/
Hey,
I just thought I would share something I made that I tested in IE6, IE8, Firefox 3.6, and Chrome 4. It allows you to resize a client-side image map based on the size of the image, so when your image resizes, your map still works how you want it to.
This is my first revision. There are a lot of easy improvements to be made. I'll post them sometime later. It should support "rect" but I only tested it with "poly". Might even work with "circle". ]]>Mon, 28 Jun 2010 09:14:28 GMThttp://snipplr.com/view/36398/variablesized-image-map-version-001/(JavaScript) get the GET variable of one URL into variable - tsunammishttp://snipplr.com/view/28812/get-the-get-variable-of-one-url-into-variable/
]]>Tue, 23 Feb 2010 19:32:33 GMThttp://snipplr.com/view/28812/get-the-get-variable-of-one-url-into-variable/(JavaScript) Accessing javascript variable from code behind and accessing code behind variable from javascript - streamthttp://snipplr.com/view/28309/accessing-javascript-variable-from-code-behind-and-accessing-code-behind-variable-from-javascript/
Many times we face situation like when we need to access the code behind variables from javascript as well as accessing javascript variable from code behind.
I can remember a practical scenario in my previous project.
The requirement was to draw a organizational chart (What is Org chart?). On mouse hover on each node of the chart a window should get opened and all the information about the particular employee should be shown there without sny kind of postback(not even partial).
So here all you have to do is, you have to get all the required values from the server in to your code behind variable and then access them from your javascript code.
How to access code behind variable value from javascript?
Step 1: Define the variable in your code behind.
Step 2:Access the variable using the '' syntax.
public/protected string codeBehindVariable = "Hello World";// Step 1
var javascriptVar='';// Step 2
Point to be noted: Remember! The code behind variable that we are accessing from the javascript that must be a class level variable to a method/function lavel variable.
public partial class _Default : System.Web.UI.Page
{
private string codeBehindVariable = "Hello World";// class elvel variable not method level
protected void Page_Load(object sender, EventArgs e)
{
}
}
The variavle access modifier muct not be private or you will the the compilation error,
Error 2 '_Default.codeBehindVariable' is inaccessible due to its protection level
How can we access javascript variable value from the code behind?
Step 1: Put a HiddenField control in your html.
Step 2: Get the hiddenfield element id using document.GetElementByID() method and set the value property to any javascript variable.
Step 3: Access the hidden field variable from the code behind to access the value(the value of the javascript variable).
// Step 1
var valToPass='Joydeep Sen';
onload=function(){
document.getElementById ('').value=valToPass;// Step 2
}
label1.Text = hiddenfield1.Value;// Step 3
I think these approaches are quite simple and straightforward. ]]>Sun, 14 Feb 2010 22:32:04 GMThttp://snipplr.com/view/28309/accessing-javascript-variable-from-code-behind-and-accessing-code-behind-variable-from-javascript/(JavaScript) Variable Variables in JS, non-window object ("globals") method - nerdfileshttp://snipplr.com/view/25117/variable-variables-in-js-nonwindow-object-globals-method/
1. Don't use (window) globals.
2. Don't use eval(). ]]>Sun, 20 Dec 2009 13:52:54 GMThttp://snipplr.com/view/25117/variable-variables-in-js-nonwindow-object-globals-method/(JavaScript) estrarre una variabile dal querystring - BoNzOhttp://snipplr.com/view/13088/estrarre-una-variabile-dal-querystring/
]]>Fri, 13 Mar 2009 10:59:03 GMThttp://snipplr.com/view/13088/estrarre-una-variabile-dal-querystring/(JavaScript) Test if variable exists - tonichttp://snipplr.com/view/11312/test-if-variable-exists/
]]>Mon, 19 Jan 2009 08:39:28 GMThttp://snipplr.com/view/11312/test-if-variable-exists/(JavaScript) Function - Get querystring variable - charmcitycoderhttp://snipplr.com/view/9742/function--get-querystring-variable/
Many thanks to bloggingdeveloper.com for this one. Works like a charm. Usage is similar to server side built-in functions. ]]>Fri, 14 Nov 2008 16:36:36 GMThttp://snipplr.com/view/9742/function--get-querystring-variable/(JavaScript) Conditionally assign a value to a variable - noahhttp://snipplr.com/view/6850/conditionally-assign-a-value-to-a-variable/
To assign a value to a variable only if some expression evaluates to true, I would usually do this:
var foo;
if (condition){
foo = "success";
}
This is Douglas Crockford's idiom and it shortens the above from 4 lines to 1.
I have understood for a while that (expr1 && expr2) evaluates to truth only if both conditions are true. What I did not get before Crockford pointed it out in his book, was that && doesn't simply return a boolean value -- it returns the result of the last expression that was evaluated.
So if both expressions evaluate to false, the result of first expression will be returned. If only one expression evaluates true, the result of the false expression will be returned. And if both expressions evaluate to truth, the result of the second expression is returned. ]]>Mon, 23 Jun 2008 08:44:59 GMThttp://snipplr.com/view/6850/conditionally-assign-a-value-to-a-variable/(JavaScript) Checking for global variable presence - zhahttp://snipplr.com/view/5762/checking-for-global-variable-presence/
/* if (globalVariable) {
But this wouldn't work. That code is actually checking to see if the defined variable globalVariable has a null value. If the variable has not been defined, that code will cause an error.
Instead, here is the code that will check for the presence of a global variable:
*/
if (window.globalVariable) { ]]>Thu, 10 Apr 2008 04:11:29 GMThttp://snipplr.com/view/5762/checking-for-global-variable-presence/(JavaScript) Grab Text from a File Ajax - 1manhttp://snipplr.com/view/2311/grab-text-from-a-file-ajax/
Very basic grab a line of text from a file then display it in an alert box. Uses other functions for loading prepareLinks() and creating the request. ]]>Tue, 13 Mar 2007 05:14:55 GMThttp://snipplr.com/view/2311/grab-text-from-a-file-ajax/(JavaScript) Get Querystring Variable - cochambrehttp://snipplr.com/view/623/get-querystring-variable/
]]>Tue, 01 Aug 2006 14:31:49 GMThttp://snipplr.com/view/623/get-querystring-variable/