Skip to main content

Posts

Showing posts with the label JavaScript

Send HTML Form Elements Value Without Using Form Tag

How to send form components value without using Form Tag in HTML, ? This example will help your to send HTML elements value from one page to another page without using HTML Form Tag. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT=""> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <BODY> <script language="javascript"> function goFor(){ var ele = document.getElementById("URL"); if(ele.value==""){ alert("Please Enter URL."); }else{ location.href="http://www.google.com?q="+ele.value; } } </script&g

How to Replace All in Javascript

How to replace all string using javascript replace function... Here is simple example replace all in javascript in replace string method. CODE: <Script Language="javascript"> var str = "This is the test string."; var rs = str.replace(/is/g,""); document.write(st); // result "Th the test string." </Script>

Center Alignment of popup window Javascript

How to centralized popup window using Javascript. see the below code. CODE: 1 :   var OpenWindows = new Object(); 2 :   function OpenWin(sPath, w, h) 3 :   { 4 :        l = (screen.width - w)/2-5; 5 :        t = (screen.height - h)/2-20; 6 :        if (l<1) l=0; 7 :        if (t<1) t=0; 8 :        sWindowName = "mainwin_" + w + "_" + h; 9 :        if(OpenWindows[sWindowName]) { 10 :             if(!OpenWindows[sWindowName].closed) OpenWindows[sWindowName].close(); 11 :        } 12 :        OpenWindows[sWindowName] = window.open(sPath, sWindowName, "left=" + l + ",top=" + t + ",width=" + w + ",height=" + h + ",scrollbars=no,menubar=no,toolbars=no,status=no"); 13 :        return OpenWindows[sWindowName]; 14 :   }

How To Change Form Action at Runtime

How to change Form action at runtime using javascript. This the example which will change html form action at runtime. CODE: 1 :   <html> 2 :   <head> 3 :   <Script Language="javascript"> 4 :   function change_action(){ 5 :   var frm_obj=document.getElementById("frm"); 6 :   frm_obj.action="http://www.google.com"; 7 :   } 8 :   </Script> 9 :   </head> 10 :   <body> 11 :   <form id="frm" action="abc.php" method="post" onsubmit="return change_action()"> 12 :   UID &nbsp;&nbsp;<input type="text"><br> 13 :   PWD <input type="Password"><br><br> 14 :   <input type="submit" value="submit"> 15 :   </form> 16 :   </body> 17 :   </html>

Change Div Position Randomly on Home Page

Change Div position randomly on home page.here is simple example which display a div randomly on homepage within available width and hight. CODE: 1 :   <Script Langauge="javscript"> 2 :   var load=true; 3 :   var div_width=300; 4 :   var div_height=200; 5 :   var top=Math.floor(Math.random()*screen.availHeight - div_height) 6 :   var left=Math.floor(Math.random()*screen.availWidth - div_width) 7 :   document.write("<div id='pic_div' style='border:1px solid black;position:absolute;width:"+div_width+";height:"+div_height+"; 8 :   text-align:center;left:0px;top:0px'>a</div>"); 9 :   var d_obj=document.getElementById("pic_div"); 10 :   d_obj.style.top=top; 11 :   d_obj.style.left=left; 12 :   </script>

How to set Javascript Cookie for Domain

var cookie_date = new Date ( ); // current date & time cookie_date.setTime ( cookie_date.getTime() + 24*60*60*1000 ); // for 1 days Syntax: document.cookie = "CookieName=CookieValue; expires=cookie expire time"; path= directories;domain=domainname"; Example: document.cookie="test=testValue;expires="+ cookie_date.toGMTString()+";path=/dir1/dir2/dir3/;domain=mytest.com";

Random Layer using javascript

Display random layer/div in javascript <HTML> <Head> <Script Language="javascript"> //global var var last_index=0; box_len=5; function ret_index() { var ran; do{ ran=Math.floor(Math.random()*box_len); if(ran==0)ran=box_len; }while(ran==last_index); last_index=ran; return ran; } function show_one(){ vBox=ret_index(); for(var i=1;i<=box_len;i++){ if(vBox!=i){ obj=document.getElementById("box_0"+i); obj.style.display="none"; }else{ obj=document.getElementById("box_0"+i); obj.style.display="inline"; } } } </Script> <Body> <a href="javascript:show_one();">show One</a> <div id='box_01' style="position:absolute;left:120;width:100;height:100;border:1px solid red;text-align:center"> <br>Box1 </div> <div id='box_02' style="position:absolute;left:240;width:100;height:100;border:1px solid red;text-align:center"> <br>Box2 </div

JavaScript Cookies Functions

Java Script Cookies Set and Get functions There are four function which is useful to work with javascript cookies. there are no predefine function in javascript so that we can use these function to work with browser cookies. here is description of functions. 1) Javascript function set_cookie(name,value) :- This is a void function take two parametters name & value. name param is used for cookies name & value is used to set cookies value. 2) Javascript function get_cookie(name) :- This string function, which return value of that particualr cookie which you pass as param. 3) Javascript function is_cookie(name) :- This is boolean function, which return true or false for cookies existence. 4) javascript function delete_cookie(name) :- This is a void function which is used to delete cookies. name param takes name of cookies which you want to delete. <Script Language="javascript"> function set_cookie(name,value){ var name=name.toLowerCase(); document.cookie=name

Javascript Trim Function Problem

There is no function to trim string in javascript. We can use following user define function to trim string using javascript. Mainly we need three type of trim function which we use in program. Right Trim Javascript User Define function. function rightTrim(str) { return str.replace(/\str+$/,""); } Left Trim Javascript User Define function. function leftTrim(str) { return str.replace(/^\str+/,""); } Trim javascript function for both left and right side. function trim(str) { return str.replace(/^\str+|\str+$/g,""); }

Flex Cache Problem

There is very big problem in flex that's cache problem. When I was developing a Rich Internet application. I faced flex cache problem in Internet Explore & Firefox browser i was stuck badly. Then I wrote this code for avoiding flex cache problem & i think it works a bit. Well still working on it. I have added this code into index.template.html which is located into flex project html-template/index.template.html. <Script Language="javascript"> var url = location.href; var ots = parseInt(url.substring(url.indexOf("=")+1,url.length))+6000; var dt = new Date(); var n = dt.getTime(); if(url.indexOf("?timeStamp=")!=-1) { if(isNumber(ots) && ots!=""){ if(nts>ots){ location.href=url.substring(0,url.indexOf("?"))+"?timeStamp="+nts; } }else{ location.href=url.substring(0,url.indexOf("?"))+"?timeStamp="+newTimeStamp; } }else{ location.href=url.substring(0,url.indexOf("?")