Tag: form validation

disable form posting using javascript

Sometimes we do not want user to submit form unless some conditions are met. In the following example, the user will be able submit form only if (s)he clicks on “I agree” checkbox. <!DOCTYPE html> <html> <head> <title>Untitled document</title> <meta charset="utf-8" /> <script language="javascript" type="text/javascript"> function enableButton() { var chk = document.getElementById("chkagree"); var btn =

validating html object array using javascript

In this example, we validate an array of checkbox, text, and radio fields. We also validate a html drop down “select” <!DOCTYPE html> <html> <head> <title>Untitled document</title> <meta charset="utf-8" /> <script language="javascript" type="text/javascript"> function validate() { var currency = document.getElementById("txtcurrency").value; var country = document.getElementById("ddlcountry"); var radsuit = document.getElementsByName("radSuit"); var chkSuit = document.getElementsByName("chkSuit"); var status=false; var

replacing words in paragraph using javascript

Sometimes it is important to replace some words from a paragraph. This can be done at client end using javascript. In the following example, we want to replace two words “class” and “javascript” from the text written in textarea. The words are replaced with “***” strings. <!DOCTYPE html> <html> <head> <title>Untitled document</title> <meta charset="utf-8" />

javascript validating required fields

One way to perform check on all the required input fields is by assigning a class name in the “class” property, and check all those fields whose “class” property is set with value “required”. The following example demonstrates that. <!DOCTYPE html> <html> <head> <title>Untitled document</title> <meta charset="utf-8" /> <style> .required { } </style> <script language="javascript"

javascript based entry checks with messages

In the following example, we perform data entry checks and highlight the input fields whose values are not provided or not provided in proper format <!DOCTYPE html> <html> <head> <title>Untitled document</title> <meta charset="utf-8" /> <style> .normal { background-color:white; } .error { background-color:orangered; } </style> <script language="javascript" type="text/javascript"> function validate() { var name = document.getElementById("txtname"); var