0
<table>
   <tbody id="add_weight">
      <tr></tr>
   </tbody>
</table>

<a onClick="edit_weights()" style="text-decoration:none !important;"><span   style="cursor:pointer; font-size:10px;">+Add more Weights.</span></a><br/><br/>

on page load there is no textbox but when i click on anchor tag a textbox opens for that i have applied a function...

<script type="text/javascript">
    var b=1;
    function edit_weights() {
        if (b==10) {
            alert("can't Add more than 10 Weight Rates");
            return false;
        }

        var table=document.getElementById("add_weight");
        var row=table.insertRow(b);
        var cell1=row.insertCell(0);

        cell1.innerHTML="<input type='text' id='edit_weight_from"+b+"' name='edit_weight_from"+b+"' style='width:100px; height:22px; float:left; margin:0px 0px 0px 0px;'/>";

        b=b+1;
     }

</script>

now everytime i click on anchor tag a new textbox comes...now what i want is that when i try to enter alphabet in this textbox it should not take it .and when i enter number then it should take it so is there any way to do it??

Zach Lysobey
  • 14,959
  • 20
  • 95
  • 149
user3138522
  • 111
  • 3
  • 4
  • 12
  • 2 questions. You're using plain javascript only, no jQuery/Underscore or similar libraries? And by 'validation' you mean you want to block user input if he enters non-numbers? – Eternal1 Feb 01 '14 at 07:42
  • yes sir...i want to block user input if he enters non_numbers...how can i achieve it...?? – user3138522 Feb 01 '14 at 07:46
  • 1
    possible duplicate of [HTML Text Input allow only Numeric input](http://stackoverflow.com/questions/469357/html-text-input-allow-only-numeric-input) – Zach Lysobey Feb 01 '14 at 07:46
  • what that means...how can i do it?? – user3138522 Feb 01 '14 at 07:48

1 Answers1

0

It doesn't have the best browser support yet (IE<10), but with HTML5, we have many new input types. One is <input type="number"> which will allow only numeric input.

In unsupported browsers it just defaults to a plain textbox (no validation). Combined with server-side validation, for some projects I can justify no JS validation on such fields for old internet explorer users. Perhaps you can to?

Zach Lysobey
  • 14,959
  • 20
  • 95
  • 149