Search code examples
javascripthtmlhtml-tablecontenteditable

How to check type of value inserted in HTML table using JavaScript


I am working on a contenteditable HTML table. I have to assure that only numeric values can be inserted, and show an alert when user tries to insert strings, or something that is not a number. How can I do this? I've searched online but I did not find anything yet.

btw, I use prompts to communicate: is there a way to deny the user to check the option "don't let the browser keep prompting things"?


Solution

  • Use the typeof operator: http://www.w3schools.com/jsref/jsref_operators.asp. Wrap it in an if statement and stop the user from proceeding.