Archivio per May, 2007

Questo script javascript mostra quanti caratteri restano in una textarea.

onload="showRemaining(document.forms['myForm'].elements['myInput']);">

<script type="text/javascript">
function showRemaining(formElement) {
var theForm = formElement.form;
var remainingDisplay = formElement.name + 'Remaining';
theForm.elements[remainingDisplay].value = formElement.maxLength -
formElement.value.length;
}
</script>
<form name="myForm">
<input type="text" name="myInput" maxlength="20"
onkeyup="showRemaining(this);">
<input type="text" name="myInputRemaining" size="2" readonly>
</form>

In questo tutorial vedremo come creare un sistema simile a quello gi gmail per allegare i file alle email. Funziona che se si clicca su aggiungi altro file, appare un box con un input per allegare il file.

html

<input type="file" name="attachment" id="attachment" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
<div id="moreUploads"></div>
<div id="moreUploadsLink" style="display:none;"><a href="javascript:addFileInput();">Aggiungi altro file</a></div>

javascript

var upload_number = 2;
function addFileInput() {
     var d = document.createElement("div");
     var file = document.createElement("input");
     file.setAttribute("type", "file");
     file.setAttribute("name", "attachment"+upload_number);
     d.appendChild(file);
     document.getElementById("moreUploads").appendChild(d);
     upload_number++;
}

        function RoundDecimalNumbers($number, $max_length)
        {
                if (strpos("".$number, ".") == false)
                        return $number;
                if (strlen("".$number) > ($max_length - 1))
                {
                        $dot_pos = strpos("".$number, ".");
                        if (($max_length - $dot_pos) > 0)
                                $number = round($number, $max_length - (strlen("".$dot_pos)));
                }                return $number;

        }

14
05

Cercare un elemento dentro un array

posted di Administrator, in php, tutorials. No Commenti

Una bella funzione php che ricerca un elemento all'interno di un array e restituisce true o false se lo trova o meno.

function FindArrayKeyByValue($arr, $find)
        {
                $found_key = false;
                $arr_keys = array_keys($arr);
                foreach ($arr_keys as $key)
                {
                        if ($arr[$key] == $find)
                        {
                                $found_key = $key;
                                break;
                        }
                }
                return $found_key;
        }

12
05

Centinaia di icone per il web gratuite

posted di Administrator, in siti web. No Commenti

 

Sul sito http://www.websiteicons.com/tab/FREE_Pixel_icons è possibile scaricare un centinaio di icone stile pixel art divise per categorie.

Questa funzione restituisce il testo che l'utente ha selezionato

function getSelectedText(){
  if (window.getSelection){
    txt = window.getSelection();
  }
  else if (document.getSelection) {
    txt = document.getSelection();
  }
  else if (document.selection){
    txt = document.selection.createRange().text;
  }
  else return;
  return txt;
}

In questo articolo vedremo come sia possibile cercare e sostituire un testo 

<script>
var str="foobar";
var val="foo";
 var search='/'+val+'/i';
 alert(str.replace(search, '<strong>'+val+'</strong>'));
</script>

function getMouseX( e ) {
    return e.pageX
        || ( e.clientX + ( document.documentElement.scrollLeft
        || document.body.scrollLeft ) );
}
function getMouseY( e ) {
    return e.pageY
        || ( e.clientY + ( document.documentElement.scrollTop
        || document.body.scrollTop ) );
}

function preloadImages() {
   if (document.images) {
        for (var i = 0; i < preloadImages.arguments.length; i++) {
               (new Image()).src = preloadImages.arguments[i];
                 }
    }
}

11
05

Ridimensionare una immagine con php

posted di Administrator, in php, tutorials. No Commenti

Creare un thumbnail da una immagine esistente. $filename il nome del file originale,mentre $tmpname l attuale filesystem nome (ad esempio il nome del file temporaneo usato nell upload di php). Ritorna una immagine che puoi mostrare come ouptut nel browser oppure salvare come file usando imagejpg(), imagepng(), etc.

function resize_image($filename, $tmpname, $xmax, $ymax)
{
    $ext = explode(".", $filename);
    $ext = $ext[count($ext)-1];
    if($ext == "jpg" || $ext == "jpeg")
        $im = imagecreatefromjpeg($tmpname);
    elseif($ext == "png")
        $im = imagecreatefrompng($tmpname);
    elseif($ext == "gif")
        $im = imagecreatefromgif($tmpname);  
    $x = imagesx($im);
    $y = imagesy($im);  
    if($x <= $xmax && $y <= $ymax)
        return $im;
    if($x >= $y) {
        $newx = $xmax;
        $newy = $newx * $y / $x;
    }
    else {
        $newy = $ymax;
        $newx = $x / $y * $newy;
    }  
    $im2 = imagecreatetruecolor($newx, $newy);
    imagecopyresized($im2, $im, 0, 0, 0, 0, floor($newx), floor($newy), $x, $y);
    return $im2;
}

web tracker