07.21.08

Stop bots from submitting contact forms

Posted in php general | at 6:41 pm by admin

I have been using this code for a while and it seems to work but i don’t think it is 100% infallible. It is used to stop robots from submitting your contact forms, or any kind of forms really. The code can be found at
:-

http://www.phpclasses.org/browse/package/3817.html

07.20.08

Javascript version of php in_array

Posted in General Javascript | at 2:59 am by admin

I was working with javascript arrays and needed to find a needle in a haystack or a value in an array. I came across this function:-

function js_in_array(the_needle, the_haystack){
   var the_hay = the_haystack.toString();
   if(the_hay == ''){
      return false;
   }
   var the_pattern = new RegExp(the_needle, 'g');
   var matched = the_pattern.test(the_haystack);
   return matched;
}

Change the visibility of a html element

Posted in General Javascript | at 2:57 am by admin

I often use this code to toggle the visibility of a HTML element on the page. It is especially useful with forms and showing different option depending on what the user selects. Here is the code:-

function ToggleVis(element){
   var Target=document.getElementById(element);
   if(Target.style.display==""){
      Target.style.display="none";
   }else{
      Target.style.display="";
   }
}

Dynamically load javascript code in page

Posted in General Javascript | at 2:56 am by admin

In the IWebBiz CMS individual content objects may need their own javascript code to process them. So I load each individual javascript file as needed. The code to do this is:-

function dhtmlLoadScript(url)
{
   var e = document.createElement("script");
   e.src = url;
   e.type="text/javascript";
   document.getElementsByTagName("head")[0].appendChild(e);
}

Is a variable a number

Posted in General Javascript | at 2:54 am by admin

Often we need to see whether a variable is a number. Here is the code:-

function IsNumeric(sText)
 
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
 
   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
 
}

Scrolling Marquee Text

Posted in General Javascript | at 2:30 am by admin

I recently had a website that needed scrolling pictures from the right to the left. It was a photo album and it achieved this with a marquee tag. I also wanted to increase the speed of the scrolling via javascript so if the users went back to the page it would be simple to scroll back to the point they left at. Here is the code:-

<div align="left">
                <button  class="FormButtons" onmouseover="scroll(50)"
onmouseout="scroll(10)"
><< Scroll Faster</button>
                <script type="text/javascript">
function scroll(speed) {
document.getElementById("scroller").scrollAmount = speed;
scroller.start();
}
              </script>
              </div>
              <marquee name="scroller" id="scroller"  behavior="slide" direction="left" loop="9999999999">
something to scroll
          </marquee>

An example of the code can be seen at http://www.sirensmodels.com