about 9 years ago
We can do validation of a form which is created in html by using javascript.
In below example if we do not put any thing in fname field, then validateName function will alert a message that Name field is empty.
eg:-
- function validateName() {
- var n = document.forms["firstform"]["fname"].value;
- if (n == null || n == "") {
- alert("Name field is empty");
- return false;
- }
- }
function validateName() { var n = document.forms["firstform"]["fname"].value; if (n == null || n == "") { alert("Name field is empty"); return false; } }
Html code
- <form name="firstform" action="test.amp";form.asp" onsubmit="return validateName()" method="post">
- Name: <input type="text" name="fname">
- <input type="submit" value="Submit">
- </form>
<form name="firstform" action="test.amp";form.asp" onsubmit="return validateName()" method="post"> Name: <input type="text" name="fname"> <input type="submit" value="Submit"> </form>
Can you help out the community by solving one of the following Cloud Computing problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)