Salta ai contenuti. | Salta alla navigazione

Strumenti personali

Data base interno JS

Gestione Array e String

HTML icon dbinterno.html — HTML, 3 kB (3668 bytes)

Contenuto del file

<html>
<head>
<script type="text/javascript" src="miojavascript.js"></script>
<script LANGUAGE="JavaScript" type="text/javascript">
<!-- Start script
var Entries = 5;	
var Separator = ";"      
var Fields = 7;	
var iName = 1;
var iFirstName = 2;
var iStreet = 3;
var iPLZ = 4;	
var iCity = 5;
var iPhone = 6;
var iEMail = 7; 	
// creazione Array               

var Data = new createArray(Entries);

Data[1] = "Cosentini;Roberto;via Righi. 14;80147;Napoli;+39-081-604594;cosentini@iol.it";
Data[2] = "Annunziata;Pasquale;via Trasaghis. 5; 00188;Roma;+39-06-33625601;mc0414@mclink.it";
Data[3] = "Rossi;Ugo;piazza Dante. 2;40120;Bologna;+39-051-236789;rossi@galaxia.it";
Data[4] = "Damiani;Carlo;via G.Cursi 12;20123;Milano;+39-02-9836728;damiani@netmag.com";
Data[5] = "Vannini;Carlo;Corso Umberto 12;80100;Napoli;+39-081-6790212;vannini@icom.it";

var LastMatch = 0; 

function createArray(length)
{
	this.length = length;
	for( var i = 1; i<= length; i++)
		this[i] = null;
	return this;		
}


function GetField(Entry,number) 
{
	var Out = "";
	var FirstChar;
	var LastChar;

	FirstChar = 0;
	LastChar = Entry.indexOf(Separator) ;
	if (number == 1) 
	{
		Out += Entry.substring(FirstChar,LastChar); 
		return Out;
	}
	if (number == Fields)
	{
		Out+= Entry.substring(Entry.lastIndexOf(Separator) + 1,Entry.length)
		return Out;
	}

	for(var i =2; i <= number; i++)
	{
		FirstChar = LastChar + 1;
		LastChar = Entry.indexOf(Separator, FirstChar);
	}
	Out += Entry.substring(FirstChar,LastChar); 
	return Out;
}

function FindNext(String, number) 
{	
	var CompareWith = "";
	for(var i = LastMatch + 1; i <=Data.length; i++)
	{
		var buf = GetField(Data[i],number);
		var bl = parseInt(buf.length);
		var sl = parseInt(String.length);
		if(bl > sl)
		{
		CompareWith = buf.substring(0,sl );
		}	
		else
		{
			CompareWith = buf;
		}
		if (CompareWith == String)
		{
			LastMatch = i;
			return i;
		}
	}
	LastMatch = 0;
	return 0;	
}

function ResetSearch()
{
	LastMatch = 0;
	for(var i = 1; i <=Fields; i++)
	{
		document.SearchForm.elements[i+3].value = "";
	}
}



function TypeNext()
{
	var SearchString = document.SearchForm.Text.value;
	var index =document.SearchForm.elements[3].options.selectedIndex + 1;
	var j = FindNext(SearchString, index);
	if (j == 0)
	{
		alert("La parola digitata non � presente nel Database. \n-Oppure- \n Lista Database terminata.");
		ResetSearch();
		return;
	}
	var buf = "";
	for(var i = 1; i <=Fields; i++)
	{
		buf = GetField(Data[j],i);
		document.SearchForm.elements[i+3].value = buf;
	}
}
</script>
</head>
<body>
<FORM NAME="SearchForm"  onSubmit = "TypeNext();return false">
<INPUT NAME="Text" TYPE="TEXT" ROWS=1 COLS=20>
<INPUT NAME="FindNext" TYPE="SUBMIT" VALUE="Cerca  >>>">
<INPUT NAME="NewSearch" TYPE="Reset" VALUE="Nuova ricerca" onClick ="ResetSearch();"><BR>
Ricerca per: <SELECT  VALUE="field" SIZE=1>
<OPTION>Cognome
<OPTION>Nome
<OPTION>Indirizzo
<OPTION>C.A.P.
<OPTION>Citt�
<OPTION>Numero telefonico
<OPTION>Indirizzo E-Mail
</SELECT><BR>
<FONT COLOR="#FF0000" FACE="Arial">Questo � il risultato:</FONT><BR>
<INPUT NAME="Result1" TYPE="TEXT" ROWS=1 COLS=15 SIZE="15"> 
<INPUT NAME="Result2" TYPE="TEXT" ROWS=1 COLS=15 SIZE="15"><BR>
<INPUT NAME="Result3" TYPE="TEXT" ROWS=1 COLS=31 SIZE="31"><BR>
<INPUT NAME="Result4" TYPE="TEXT" ROWS=1 COLS= 5 SIZE="5">
<INPUT NAME="Result5" TYPE="TEXT" ROWS=1 COLS=25 SIZE="25">
<INPUT NAME="Result6" TYPE="TEXT" ROWS=1 COLS=31 SIZE="31"><BR>
<INPUT NAME="Result7" TYPE="TEXT" ROWS=1 COLS=30 SIZE="30">
</FORM>
</body>
</html>