Posts

Allow only numbers to be typed in a textbox

You could subscribe for the onkeypress event: <input type = "text" class = "textfield" value = "" id = "extra7" name = "extra7" onkeypress = " return isNumber ( event ) " /> and then define the  isNumber  function: function isNumber ( evt ) { evt = ( evt ) ? evt : window . event ; var charCode = ( evt . which ) ? evt . which : evt . keyCode ; if ( charCode > 31 && ( charCode < 48 || charCode > 57 )) { return false ; } return true ; } <input type='number' class='qty' name='' value='' min='0' max='99' onkeypress='return isNumberKey(event, false)' /></td> function isNumberKey(evt, decimal) { var charCode = (evt.which) ? evt.which : evt.keyCode if (decimal == true && charCode == 46) return true; if (charCode > 31 ...

preventing form from submitting when input field is empty

<html> <head> <title> STUDENT FORM </title> <script type = "text/javascript" > function empty () { var x ; x = document . getElementById ( "roll-input" ). value ; if ( x == "" ) { alert ( "Enter a Valid Roll Number" ); }; } </script> </head> <body > <h1 align = "center" > student details </h1> <div id = "input" > <form action = 'retrive.php' method = 'get' > <fieldset> <legend> Get Details </legend> <dl> <dt><label for = "roll-input" > Enter Roll Number </label></dt> <dd><input type = "text" name = "roll" id = "roll-input" ><dd> ...

JavaScript validation for empty input field

<script type = "text/javascript" > function validateForm () { var a = document . forms [ "Form" ][ "answer_a" ]. value ; var b = document . forms [ "Form" ][ "answer_b" ]. value ; var c = document . forms [ "Form" ][ "answer_c" ]. value ; var d = document . forms [ "Form" ][ "answer_d" ]. value ; if ( a == null || a == "" , b == null || b == "" , c == null || c == "" , d == null || d == "" ) { alert ( "Please Fill All Required Field" ); return false ; } } </script> <form method = "post" name = "Form" onsubmit = " return validateForm () " action = "" > <textarea cols = "30" rows = "2" name = "answer_a" id = "a" ...