Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
<body onload="init();">
  
  <fieldset id="field">
    <legend>SEARCH ENGINE</legend>
      <center><div>
         <label for="txt">Enter the key word: </label>
         <input id="input" type="text" name="format" id="txt" value="" required>
         <button onClick="submitSearch()" type="search" id="inputImg">Search</button>
         <sub id="sub">no matches founded</sub>
      </div>
  
</fieldset>
 
<table id="myTable">
 <caption></caption>  
  <tr>
    <th scope="col">ID</th>
    <th scope="col">Given Name</th>
    <th scope="col">Family Name</th> 
    <th scope="col">Age</th>
    <th scope="col">City</th>
  </tr>
  
</table>
  <center><button onClick="previous();">Previous page</button>
  <button onClick="next();">Next page</button>
              
            
!

CSS

              
                table {
  width:100%;
  border:1px solid;
  border-collapse: collapse;
}


tr, th, td {
  border:1px solid;
  font-family:courier;
}

td {
  text-align:center;
  padding:10px;
  
}
fieldset {
  padding:10px;
  border-radius:10px;
}

label {
  display:inline-block;
  margin-bottom:10px;
}



#input:invalid {
  background-color:pink;
}

#input:valid {
  background-color:lightgreen;
}
#sub{
  visibility:hidden;
}

              
            
!

JS

              
                
  var inicio=0;
  var final=15;
function submitSearch() {
  document.getElementById("sub").style.visibility="hidden";
  var found=0;
  var wordToSearch = document.getElementById("input").value;
  if(wordToSearch==""){
    
    console.log("entro en el alert");
    alert("Please type somthing to search");
      
  }
  var table = document.getElementById("myTable");
  for(var i=1;i<table.rows.length;i++){
    var objCells = table.rows.item(i).cells;
    var rowToCheck = table.rows[i].getElementsByTagName("td");
    for(var j=0;j<rowToCheck.length;j++){
      if(rowToCheck[j].innerHTML.toLowerCase()==wordToSearch.toLowerCase()){
        console.log("entro en el for j")
        rowToCheck[j].style.backgroundColor="lightgreen";
        found++;
      }
      else{
        
        rowToCheck[j].style.backgroundColor="white";
      }
    }
  }
  
  if(found!=0){
    document.getElementById("sub").innerHTML=found+" matches found";
    
  }
  else{
    document.getElementById("sub").innerHTML="no matches found";
  }
  document.getElementById("sub").style.visibility="visible";
  console.log("number of matches: "+found)
  
}
var objectData={
  cities:["Malaga","New York","Madrid","London","Paris","Fuengirola","Roma","Venecia","Honk Kong","Tokyo","Melbourne","Damasco","Bombay","Buenos Aires","San Francisco","Lima","Bogota","Manchester","Toulouse","Berlin"],
  givenNames:["Michel","Marcos","Sandra","Rafael","Ketty","Victor","Ines","Sylvie","Alvaro","Roberto","Melissa","Carla","Emma","Julia","Valeria","Irene","Sonia","Eva","Lucas","Bruno"],
  familyNames:["Aguirre","Duque","Duniol","Miñarro","Lopez","Garcia","Gomez","Fernandez","Skywalker"]
 };
function createRandomTable(){
  for(var i=0;i<500;i++){ 
    
  var randomGivenName=objectData.givenNames[Math.round((Math.random()*19))];
  var randomFamilyName=objectData.familyNames[Math.round((Math.random()*8))];
  var randomAge=Math.round((Math.random()*120));
  var randomCity=objectData.cities[Math.round((Math.random()*19))];
  var table = document.querySelector("#myTable");
  var row = table.insertRow();
  row.innerHTML = "<td>"+i+"</td><td>"+randomGivenName+"</td><td>"+randomFamilyName+"</td><td>"+randomAge+"</td><td>"+randomCity+"</td>";
  row.style.display="none";
  
  
  
  }
  }
  
function showSelectedRows(){ 
var rows = document.getElementById("myTable").rows;
for (var i = 0; i < rows.length-1; i++) {
if (i < inicio || i > final-1)
rows[i+1].style.display = 'none';
else
rows[i+1].style.display = '';
}
}
  

function previous(){
  if(inicio!=0){
    inicio-=15;
    final-=15;
    console.log(inicio);
    console.log(final);
  }
    showSelectedRows();
}
function next(){
  if(final<499){
    inicio+=15;
    final+=15;
    console.log(inicio);
    console.log(final);
  }
  showSelectedRows();
}
function init(){
  createRandomTable();
  showSelectedRows();
}

              
            
!
999px

Console