lundi 6 juin 2016

Is possible search an element array from input?


I'm creating a little script for try to search an element array in input.

var modulo = document.getElementById("modulo").value;
var link = [
  "http://ift.tt/Wd3UGC",
  "http://ift.tt/QAsbzd",
  "http://ift.tt/1oEnhTB",
];
if(modulo.indexOf(link) > -1) {
  alert("Your site is:" + modulo);
} 

else {
  alert("Sorry, I don't found:" + modulo)
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Search element in array</title>
</head>
<body>
<input type="text" id="modulo" class="form">
</body>
</html>

Anyone can explain me how to do (if there's another way for do it better, anyone say me it), and why my code don't runs? Thanks! I explain you my code: I've used var modulo for contain the value of input. Then I've created a variable for contain link. Then if-else statement and indexOf for search/found it.

Aucun commentaire:

Enregistrer un commentaire