Sunday, July 22, 2012

How to get java script variable value on server side

The answer is Hidden field or any input control.

You just need to take hidden field and set the value of  java script variable on hidden filed .like below

var javascriptvariable='some value'; 
$('#hiddenfield').val(javascriptvariable);
 
 
Now on server side you can get the hidden field which is 
actually java script variable  value 
 
String hdnvalue=hiddenfield.value;
 
I have used Jquery val function to set the value .
 You can use val function of jquery  in
two ways to get the value just use the 
 $('#hiddenfield').val(
 
and for setting the value you need to pass 
the value as argument in val function 
like this 
 
 
 $('#hiddenfield').val('31october') 
 alert($('#hiddenfield').val() );
 
 
you can check live demo here .
 
http://jsfiddle.net/VaKfP/255/
 
 
 I love http://jsfiddle.net/  for jquery code sharing.  
 
 
Thanks   

No comments:

Post a Comment