javascript - Search data from the table is not working -


i working on javascript. in code have table , textbox. when enter data in textbox should show particular value typed doesn't search data table. how search data in table?i have provided link below.

http://jsfiddle.net/surwn/

       <table name="tablecheck" class="data" id="results" >       <thead>     <tr ><th>&nbsp;</th>         <th>&nbsp;</th>         <th><center> <b>course code</b></center></th>     <th><center>course name</center></th></tr>       </thead>          <tbody>         <tr id="rowupdate" class="tableheaderfooter">         <td>             <center> <input    type="text"    name="input"    value="course" ></center>             <center> <input    type="text"    name="input"    value="course1" ></center>             <center> <input    type="text"    name="input"    value="course2" ></center>         </td>         <td>             <center> <input    type="text"    name="input"    value="subject" ></center>             <center> <input    type="text"    name="input"    value="subject1" ></center>             <center> <input    type="text"    name="input"    value="subject2" ></center>          </td>             </tr>             </tbody>           </table >          <form action="#" method="get" onsubmit="return false;">            <label for="q">search here:</label><input type="text" size="30" name="q" id="q" value="" onkeyup="dosearch();" />           </form>        <script> function dosearch() {     var q = document.getelementbyid("q");     var v = q.value.tolowercase();     var rows = document.getelementsbytagname("tr");     var on = 0;     (var = 0; < rows.length; i++) {         var fullname = rows[i].getelementsbytagname("td");         fullname = fullname[0].innerhtml.tolowercase();         if (fullname) {             if (v.length == 0 || (v.length < 3 && fullname.indexof(v) == 0) || (v.length >= 3 && fullname.indexof(v) > -1)) {                 rows[i].style.display = "";                 on++;             } else {                 rows[i].style.display = "none";             }         }     }  } 

i highlight few things code:

  • in code, loop starts 0, table has first row header row, not contain "tr" elements. hence function not working.
  • if start loop 1, need go through input element search value. existing approach wont work.

in case of loop starting 1, fullname variable this:

may have modify comparison logic fetching value of input fields.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -