Dartcalculators - darts blog
 
>>> www.dartcalculators.com <<<
 

Thursday, September 14, 2006

PHP get request

PHP get request

Example
(html)
../graph.php?gameType=500&valuesOne=501,321,141,0&valuesTwo=501,321,141'/>

(php)
$gameType = $_GET["gameType"];

PHP for loop

For loop in php to determine min value for array.

Example

for ($i=0; $i=<10); $i++){
if ($Values[$i]<$min){$min=$Values[$i];}
}

PHP include file

Include function for including files in php.

Example
(php)

//determine root
$rootpath = $_SERVER['DOCUMENT_ROOT'];

//include footer
include "$rootpath/php/footer.php";

Monday, September 11, 2006

Javascript Set focus

You can use this function to set the focus or prompt to an inputfield, link image etc.

Example
(javascript)

function setFocus(){
//prompt input field total
document.getElementById("darttotal").focus()
}

Javascript switch

Javascript with a switch and if else structure.
I used it to determine the dart value for each dart.

Example
(javascript)

function calculateValueDart(dart, dartValue)
{
switch (dart)
{
case "DB" :
dartValue = '50'
return dartValue
case "B" :
dartValue = '25'
return dartValue
default :
//can still be D, T or normal etc
var doubleTriple = dart.substr(0,1)
if (doubleTriple == 'D' doubleTriple == 'T')
{
var actValue = dart.substr(1,2)
switch (doubleTriple)
{
case "D":
dartValue = 2 * parseInt(actValue)
return dartValue
case "T":
dartValue = 3 * parseInt(actValue)
return dartValue
}

}
else
{
dartValue = dart
return dartValue
}
} //end switch
}

Friday, September 08, 2006

Javascript keypress results in action

This javascript I used to catch a keystroke and perform an action.
It works in Firefox and IE.

Example
(javascript)
document.onkeypress=keyPressed;

function keyPressed(e){
var keyCode=(e)? e.which :event.keyCode;
if(keyCode==122)
calculateScore("One")
if(keyCode==109)
calculateScore("Two")
if(keyCode==113)
keyWinner("One")
if(keyCode==112)
keyWinner("Two")
if(keyCode==97)
checkUndo("One")
if(keyCode==108)
checkUndo("Two") }

Javascript numbers only

This script can be used for input fields which may contain only numbers.

Example
(html)
onKeyPress="return numbersonly(this, event)"

(javascript)
function numbersonly(myfield, e, dec){
var key;
var keychar;

if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) (key==0) (key==8) (key==9) (key==13) (key==27) )
return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
return true;
// decimal point jump
else if (dec && (keychar == "."))
{ myfield.form.elements[dec].focus();
return false;
}
else
return false;
}

Bookmark IE and firefox

Bookmark which works in Firefox and internet explorer.

Example
(html in 'a' tag)
href=javascript:addBookmark("http://www.dartcalculators.com","Dartcalculators%20-%20Free%20to%20use%20dart%20calculators") title="Bookmark www.dartcalculators.com">

(javascript)
function addBookmark(url,desc){
var bookmarkurl = url;
var bookmarktitle = desc;
var nonie = 'Sorry, only Mozilla Firefox and Internet Explorer support this method to add a bookmark/favourite\n But please feel free to visit the site\'s home page to add a bookmark manually';

if (window.sidebar) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(bookmarktitle, bookmarkurl,"");
} else if(document.all){ // IE Favourites
window.external.AddFavorite(bookmarkurl,bookmarktitle);
} else {
alert(nonie);
}
}

Onload Javascript

The onload can be used for many things.
You can use it for instance for maximizing your window or set a prompt.

Example
(javascript)
window.onload=function() {
setFocus();
maximizeWin()
}


function maximizeWin() {
if (window.screen)
{
var aw = screen.availWidth;
var ah = screen.availHeight;
window.moveTo(0, 0);
window.resizeTo(aw, ah);
}
}

function setFocus(){
document.getElementById("darttotal").focus()
//or set a set multiline to bottom
document.formulier.multiLinePlayerOne.scrollTop = document.formulier.multiLinePlayerOne.scrollHeight;
document.formulier.multiLinePlayerTwo.scrollTop = document.formulier.multiLinePlayerTwo.scrollHeight;
return true
}

Javascript clear field on focus

When a field gets focus it must be cleared.
It's used by filling in the score in the dart claculators.

Example
(html)
onfocus="clearDart(this)

(javascript)
function clearDart(Input)
{
Input.value = ''
}

Thursday, September 07, 2006

.htaccess

htaccess (Hypertext Access) is the default name of Apache's directory-level configuration file. It provides the ability to customize configuration directives defined in the main configuration file. The configuration directives need to be in .htaccess context and the user needs appropriate permissions (wikipedia).

Examples:

Execute php in html file
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html

I used this one for blogger because it generates html using a template.
In the templade I included php for the menu.
Now it executes the php in the html file and the menu is included as you can see.

Make your own errorpages
ErrorDocument 404 http://www.dartcalculators.com/errorpages/notfound.php
ErrorDocument 503 http://www.dartcalculators.com/errorpages/serviceunavailable.php

Redirect to your site without typing www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^dartcalculators.com$
RewriteRule (.*) http://www.dartcalculators.com/$1 [R=Permanent]


 
Thanks Disclaimer Last update: 17-07-2008
 
5