Archive

Archive for the ‘Snippets’ Category

OnChange and redirect

October 4th, 2008

i using these code to redirect once the user select an option from a select menu

<select onChange="location=this.value">
<option id="flcikr" value="http://flickr.com" selected="selected">Flickr</option>
<option id="delicious" value="http://del.icio.us" >Del.icio.us</option>
<option id="netvibes" value="http://netvibes.com" >Netvibes</option>
<option id="facebook" value="http://facebook.com" >Facebook</option>
<option id="rememberthemilk" value="http://rememberthemilk.com">RTM</option>
</select>

Snippets , ,

Set Cookie by javascript

October 4th, 2008

Javascript that i use to set cookie

function setCookie(n, v) {
var cookieStr = "";
var date = new Date();
date.setTime(date.getTime()+(3*30*24*60*60*1000));
var expiry = "; expires="+date.toGMTString();
cookieStr = n + " = " + v + ";expires="+expiry+";path=/ "  ;
document.cookie = cookieStr;
}

Snippets , ,

Checking on repeat number

October 4th, 2008

There is this validation i need to do today , to check the value is it a repeat number, example 111111 or 22222 is not allow, but 1112222 or 222333 is ok. So this is what i come out with

$same=(substr_count($text,$text[0]) == strlen($text))? TRUE : FALSE;

  • what does function substr_count(words,character) do ? if actually checking the character that you supply through the entire words and return the total number that character been use.
  • a word is actually an array of character , that’s why $text[0] means the first character in the word
  • strlen() is use to return total number of character in a word
  • one of the good tactic i learn here Variable=(Condition):condition true value ? condition false value

By using the first char compare to the whole words, it should return me the same number of total length of the word, because what i try to find out is is this word full with the same number.

Snippets ,