Avance Zone

Technical Experts Zone Blogs

Find elements in form GetElementById Javascript

Many time we find javascript error that the element is found or not initialized in the form.

<script type="text/javascript">
 
for (i=1;i<=document.FORMNAME.elements.length;i++)
{
alert(document.FORMNAME.elements[i].name);
}
</script>

Use the above function by replacing with your formname . It will alert all the detected ID inside the form element. This helps us to troubleshoot the scope of elements in the form

javascript right click – disable right click To avoid view source or steal Images

Here is the simple way to make the visitor not to steal your webpage image or source, You can use this for Any web designs – html/php/asp.net 

Insert this html with your source code

Way 1

<img src=”PicFileName.gif” height=”24″ width=”100″ onContextMenu=”return false;”>
<img src=”PicFileName.gif” height=”24″ width=”100″ onContextMenu=”alert(’Avance Zone Alert!’);return false;”>
<img src=”PicFileName.gif” height=”24″ width=”100″ onContextMenu=”alert(’Visitor! Don\’t Steal my picture!’);return false;”>
Way 2

In body onload call the javascript 
<body onContextMenu =”callme();”>
In head introduce this below lines
<script type=”text/javascript” language=”javascript”>
    function callme()
    {
alert(’Visitor! Don\’t Steal my picture!’);
return false;
}
</script>

javascript page redirect

You can add this Meta tag :

<meta http-equiv=”Refresh” content=”8;URL=http:// www.example.com/somepage.html”>

Calling A javaScript functionwith Time and Delay :

<body onload=”timer=setTimeout(’callme()’,100)”>
<script language=”JavaScript”>
<!–
var time = null
function callme() {
window.location = ‘http://www.avancezone.com’
}
//–>
</script>

Insert The Body tag and the function CALLME will be call in 100ms and your page will be redirected to other .

To redirect the page immediately by script :

<script type="text/javascript">
<!--
window.location = "http://www.google.com/"
//-->
</script>

Avoid Or Donot Allow user To Enter Space | JavaScript Exprestion

Avoid Or Donot Allow user To Enter Space | JavaScript Exprestion
Just put range 1 to 9 in exp if you want to allow number also

<form onsubmit=”return formValidator()” method=”POST” action=”arv.php”>
<script type=’text/javascript’>
function formValidator(){
  var name = document.getElementById(’x1′);
       if(Validator(name, “dont put space”)){
  }
  return false;
  }

function Validator(elem, helperMsg){
 var alphaExp = /^[a-zA-Z]+$/;
 if(elem.value.match(alphaExp)){
  return true;
 }else{
  alert(helperMsg);
  return false;
 }
}
</script>
        <input name=”name” value=”" type=”text” id=”x1″></td>
        <input value=”submit” onclick=”getFormBody()” type=”submit”>
</script>

JavaScript Onclick Status Message

<script language=”javascript”>
  function scroll()

  {
   var txt=” Loading your page…”;
   var len=txt.length;
   var width=100;
   var pos=0;
   pos++;
   var str=”";
   if(pos==len) pos=1-width;
    if(pos<0){
     for(var i=1;i<=Math.abs(pos);i++) str +=” “;
      str += txt.substring(0,width-i+1);
    }else
     str = txt.substring(pos,pos+width);
   window.status=str;
   setTimeout(”scroll()”,150);
  }

</script>
<a onClick=”scroll();return true;” href=”#”>hello</a>

Make Images rool Animation | JavaScript Tricks

Type the below code in the address bar in any webpage that has some images… And Have the fun…

javascript:R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.getElementsByTagName(”img”); DIL=DI.length; function A(){for(i=0; i-DIL; i++){DIS=DI[ i ].style; DIS.position=’absolute’; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+”px”; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+”px”}R++}setInterval(’A()’,5); void(0);
Enjoy the animations Rooollll Ooooooonnnnnn…..

Edit Or Copy Any Web Pages | Java Script Tricks

Just Go the web page you want to edit or copy and type the below code in the address bar and press enter

javascript:document.body.contentEditable=’true’; document.designMode=’on’; void

Try this and Enjoy…..

Status bar scroll message

Status bar scroll bar message java script

<SCRIPT LANGUAGE=”JavaScript”>
<!– Start of scroller script
var scrollCounter = 0;
var scrollText = ” CALL +919894160363… HI THIS IS ARVIND’S HOMEPAGE.. CALL +919894160363… SUPPORT FOR THE WEBSITE DEVELOPMENT.. CALL +919894160363… HAVE A GREAT DAY.. THANK YOU”;
var scrollDelay = 70;
var i = 0;

while (i ++ < 140)
scrollText = ” ” + scrollText;

function Scroller()
{
window.status = scrollText.substring(scrollCounter++,
scrollText.length);
if (scrollCounter == scrollText.length)
scrollCounter = 0;
setTimeout(”Scroller()”, scrollDelay);
}

Scroller();
// End of scroller script –>
</SCRIPT>

|