javascript - Check if the number of a textbox is greater than number entered array of textbox's -


i trying compare value of single text box value "totalmarkstoall" multiple array of text box's "marksscored", below java script comparing on key function.

what unable if value of "marksscored" perticuler text box greater "totalmarkstoall" shows pop :but should erase value or should not allow enter.

function scorecompare(idval) {      var marksscored = idval;        var totalmarkstoall = document.getelementbyid("totalmarkstoall").value;      if (parseint(marksscored) > parseint(totalmarkstoall))      {          alert("greater total mrks");      } else {        }  }
<input id="totalmarkstoall" type="number" style="border: 1px solid #dbdbdb;" placeholder="enter total marks"></input>  <table>      <tr>          <td>              <input type="text" name="marksscored[]" id="marksscored[0]" value="" onkeyup="scorecompare(this.value);"/>          </td>      </tr>      <tr>          <td>              <input type="text" name="marksscored[]" id="marksscored[1]" value="" onkeyup="scorecompare(this.value);"/>          </td>      </tr>      <tr>          <td>              <input type="text" name="marksscored[]" id="marksscored[2]" value="" onkeyup="scorecompare(this.value);"/>          </td>      </tr>  </table>

if know inputfield value came from.

html:

<table> <tr>     <td>         marksscored array of text box's     </td> </tr> <tr>     <td>         <input type="text" name="marksscored[]" id="marksscored[0]" value="" onkeyup="scorecompare(this);">     </td> </tr> <tr>     <td>         <input type="text" name="marksscored[]" id="marksscored[1]" value="" onkeyup="scorecompare(this);">     </td> </tr> <tr>     <td>         <input type="text" name="marksscored[]" id="marksscored[2]" value="" onkeyup="scorecompare(this);">     </td> </tr>  </table> 

js:

function scorecompare(idval) {    var marksscored = idval;     var totalmarkstoall = document.getelementbyid("totalmarkstoall").value;    if (parseint(marksscored.value) > parseint(totalmarkstoall))     {     alert("greater  total mrks");    //do things inputfield marksscored    } else {     }  } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -