<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr</title>
<link>http://snipplr.com/language/javascript/tags/variable</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Wed, 19 Jun 2013 23:36:32 GMT</pubDate>
<item>
<title>(JavaScript) Javascript revealing module pattern template - coprolit</title>
<link>http://snipplr.com/view/50765/javascript-revealing-module-pattern-template/</link>
<description><![CDATA[ <p>"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!)</p> ]]></description>
<pubDate>Thu, 17 Mar 2011 08:40:45 GMT</pubDate>
<guid>http://snipplr.com/view/50765/javascript-revealing-module-pattern-template/</guid>
</item>
<item>
<title>(JavaScript) Variable-sized Image Map, version 0.01 - xtknight</title>
<link>http://snipplr.com/view/36398/variablesized-image-map-version-001/</link>
<description><![CDATA[ <p>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".</p> ]]></description>
<pubDate>Mon, 28 Jun 2010 09:14:28 GMT</pubDate>
<guid>http://snipplr.com/view/36398/variablesized-image-map-version-001/</guid>
</item>
<item>
<title>(JavaScript) get the GET variable of one URL into variable - tsunammis</title>
<link>http://snipplr.com/view/28812/get-the-get-variable-of-one-url-into-variable/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Tue, 23 Feb 2010 19:32:33 GMT</pubDate>
<guid>http://snipplr.com/view/28812/get-the-get-variable-of-one-url-into-variable/</guid>
</item>
<item>
<title>(JavaScript) Accessing javascript variable from code behind and accessing code behind variable from javascript - streamt</title>
<link>http://snipplr.com/view/28309/accessing-javascript-variable-from-code-behind-and-accessing-code-behind-variable-from-javascript/</link>
<description><![CDATA[ <p>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.</p> ]]></description>
<pubDate>Sun, 14 Feb 2010 22:32:04 GMT</pubDate>
<guid>http://snipplr.com/view/28309/accessing-javascript-variable-from-code-behind-and-accessing-code-behind-variable-from-javascript/</guid>
</item>
<item>
<title>(JavaScript) Variable Variables in JS, non-window object ("globals") method - nerdfiles</title>
<link>http://snipplr.com/view/25117/variable-variables-in-js-nonwindow-object-globals-method/</link>
<description><![CDATA[ <p>1. Don't use (window) globals.
2. Don't use eval().</p> ]]></description>
<pubDate>Sun, 20 Dec 2009 13:52:54 GMT</pubDate>
<guid>http://snipplr.com/view/25117/variable-variables-in-js-nonwindow-object-globals-method/</guid>
</item>
<item>
<title>(JavaScript) estrarre una variabile dal querystring - BoNzO</title>
<link>http://snipplr.com/view/13088/estrarre-una-variabile-dal-querystring/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Fri, 13 Mar 2009 10:59:03 GMT</pubDate>
<guid>http://snipplr.com/view/13088/estrarre-una-variabile-dal-querystring/</guid>
</item>
<item>
<title>(JavaScript) Test if variable exists - tonic</title>
<link>http://snipplr.com/view/11312/test-if-variable-exists/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 19 Jan 2009 08:39:28 GMT</pubDate>
<guid>http://snipplr.com/view/11312/test-if-variable-exists/</guid>
</item>
<item>
<title>(JavaScript) Function - Get querystring variable - charmcitycoder</title>
<link>http://snipplr.com/view/9742/function--get-querystring-variable/</link>
<description><![CDATA[ <p>Many thanks to bloggingdeveloper.com for this one. Works like a charm. Usage is similar to server side built-in functions.</p> ]]></description>
<pubDate>Fri, 14 Nov 2008 16:36:36 GMT</pubDate>
<guid>http://snipplr.com/view/9742/function--get-querystring-variable/</guid>
</item>
<item>
<title>(JavaScript) Conditionally assign a value to a variable - noah</title>
<link>http://snipplr.com/view/6850/conditionally-assign-a-value-to-a-variable/</link>
<description><![CDATA[ <p>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 &amp;&amp; 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 &amp;&amp; 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.</p> ]]></description>
<pubDate>Mon, 23 Jun 2008 08:44:59 GMT</pubDate>
<guid>http://snipplr.com/view/6850/conditionally-assign-a-value-to-a-variable/</guid>
</item>
<item>
<title>(JavaScript) Checking for global variable presence - zha</title>
<link>http://snipplr.com/view/5762/checking-for-global-variable-presence/</link>
<description><![CDATA[ <p>/* 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) {</p> ]]></description>
<pubDate>Thu, 10 Apr 2008 04:11:29 GMT</pubDate>
<guid>http://snipplr.com/view/5762/checking-for-global-variable-presence/</guid>
</item>
<item>
<title>(JavaScript) Grab Text from a File Ajax - 1man</title>
<link>http://snipplr.com/view/2311/grab-text-from-a-file-ajax/</link>
<description><![CDATA[ <p>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.</p> ]]></description>
<pubDate>Tue, 13 Mar 2007 05:14:55 GMT</pubDate>
<guid>http://snipplr.com/view/2311/grab-text-from-a-file-ajax/</guid>
</item>
<item>
<title>(JavaScript) Get Querystring Variable - cochambre</title>
<link>http://snipplr.com/view/623/get-querystring-variable/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Tue, 01 Aug 2006 14:31:49 GMT</pubDate>
<guid>http://snipplr.com/view/623/get-querystring-variable/</guid>
</item>
</channel>
</rss>