Almeno prova a studiare un minimo JS prima di provare a sviluppare.
<input type="text" name="prova" id="prova" />codice:Array.prototype.isArray=1; Array.prototype.contains = function(item){ for(var i = 0; i < this.length; i++){ if(this[i] == item) return true; } return false; } Array.contains = function(item, arr){ if(!arr.isArray){ var e = new Error('The second argument must be an Array'); e.message = 'The second argument must be an Array'; throw e; } for(var i = 0; i < arr.length; i++){ if(arr[i] == item) return true; } return false; } var ILTUOARRAY = ['Qui', 'Devi', 'Metterci', 'I', 'Tuoi', 'Valori']; function test(id){ var elem = document.getElementById(id); var result = ILTUOARRAY.contains(elem.value); alert("Il valore del text box " + (result ? 'è contenuto' : 'non è contenuto')+" nell'array"); }
<input type="button" onclick="test('prova')" value="Invia" />
Cliccando su Invia verrà chiamata la funzione test() con un argomento passato.
L'argomento è l'ID dell'input dal quale estrarre il valore da controllare.
ILTUOARRAY dovrà contenere le parole che vuoi controllare.
N.B. la ricerca è casesensitive, cioè fa differenza tra "Ciao" e "ciao".

Rispondi quotando