How To Access Cookie Without any special Charecters

Generally, when we access javascript, wild card charecters are replaced by some special symbols (like +,% etc). This code is for accessing cookie value withour any special chacters. Try It.

//Reading Cookie

function ReadCookie(n) {
var cookiecontent = new String();
if(document.cookie.length > 0) {
 var cookiename = n+ ‘=’;
 var cookiebegin = document.cookie.indexOf(cookiename);
 var cookieend = 0;
 if(cookiebegin > -1) {
  cookiebegin += cookiename.length;
  cookieend = document.cookie.indexOf(“;”,cookiebegin);
  if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
  cookiecontent = document.cookie.substring(cookiebegin,cookieend);
 
  }
 }
return unescape(cookiecontent);
} //  This Code is for reading cookie value. But the output will consist of  ‘+’ sign in the place wild card charecters. To remove this ‘+’

//use the following function.

function get_body()
 {
  var ind = document.form2.lstmessage.selectedIndex;
      var string=ReadCookie(ind);
      var strReplaceAll = string;
      var intIndexOfMatch = strReplaceAll.indexOf( “+” );
 
      // Loop over the string value replacing out each matching
      // substring.
      while (intIndexOfMatch != -1){
      // Relace out the current instance.
       strReplaceAll = strReplaceAll.replace( “+”, ” ” );
 
      // Get the index of any next matching substring.
      intIndexOfMatch = strReplaceAll.indexOf( “+” );
      }
 
      //alert( strReplaceAll );
      document.form2.txtbody.value = strReplaceAll;    
 }
Cookies in Javascript

/ _________________Function To Create Cookie In Javascript____________________ //
function createCookie(name,value,days) {
    if (days) {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000))
      var expires = “; expires=”+date.toGMTString()
      }
      else var expires = “”
      document.cookie = name+”=”+value+expires+”; path=/”;
 }
 
// _________________Function To Read Cookie In Javascript____________________ //
 
function ReadCookie(n) {
  var cookiecontent = new String();
 if(document.cookie.length > 0) {
 var cookiename = n+ ‘=’;
 var cookiebegin = document.cookie.indexOf(cookiename);
 var cookieend = 0;
 if(cookiebegin > -1) {
  cookiebegin += cookiename.length;
  cookieend = document.cookie.indexOf(“;”,cookiebegin);
  if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
  cookiecontent = document.cookie.substring(cookiebegin,cookieend);
 
  }
 }
return unescape(cookiecontent);
} // function ReadCookie()
 
Note : If The cookie contents consist of some ‘+’ symbol then use the following code to filter the cookie contect. The
Following function is to remove the + symbols from the cookie content. It can be used for removing other special charecters from the cookie content. To use the following code to remove other special charecters, simple replace the ‘+’ symbol by the special symbol in star(//***********************//) marked line..
 
      var string=ReadCookie(ind);
      var strReplaceAll = string;
      var intIndexOfMatch = strReplaceAll.indexOf( “+” ); //***********************//
 
      // Loop over the string value replacing out each matching
      // substring.
      while (intIndexOfMatch != -1){
      // Relace out the current instance.
       strReplaceAll = strReplaceAll.replace( “+”, ” ” );
 
      // Get the index of any next matching substring.
      intIndexOfMatch = strReplaceAll.indexOf( “+” );
      }
 
 
Author – Dhiraj Das
From – Skillhut

Handling forms in Javascript

This lesson will give an idea how to start using javascripts in forms

<HTML>
<BODY>
<SCRIPT LANGUAGE=javascript>
<!–
     function f1(){
     document.write(MyForm.name,”<Br>”,MyForm.textname.value,”<Br>”,MyForm.length)
     }
//–>
</SCRIPT>
</BODY>
<FORM action=”" method=POST name=MyForm onclick=”f1()”>
<INPUT type=”text” name=textname value=”Broken Arrow”>
</FORM>
</HTML>

Iteration in JavaScript

A lesson for the beginners – how to use iteration in Javascript

<html>
<body>
<script>
   <!–
           b=1      
           while (b>6){
                b= document.write(b);b+1;
           }
           document.write(b,”<br>”);
      –>
</script>
</body>
</html>

Alert in Javascript

This lesson will help the beginners to handle alerts in JavaScripts

<html>
<head>
<script language=”javascript”>
<!–
function f1()
 {
 alert(“Skill Hut”); // Message ‘Skill Hut’ will be displayed
 }
–>
</SCRIPT>
</head>
<body color=white>
Move your mouse over <a href=”" onMouseover=”f1()”>here</a>
</body>
</html>