Click here to Skip to main content
12,072,067 members (58,410 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Javascript
Hi,
I have a form with certain fields to be filled in mandatorily.
If user doesn't fill mandates,onclick of submit button error message has to popup.
The error message has default text as : "Before submitting this form,make sure the following mandatory fields are completed:"
along with this the unfilled field names will be appended as error msg.
Following is the logic i tried..
But it doesnt seem to work....Can anyone please suggest me to improvise it?



function ExitForm(){
var msg = '';
var elem = document.form.elements;
var flag = 0;
//
condition to check if a field is filled. If no,
msg+= "\n"+"text1"
.
.
.
for textfields,textareas,radiobutton,dropdownlist
//

for(i=0;i<=elem.length;i++){

var ele = elem[i];

if(ele.type == "text" || ele.type == "radio" || ele.type == "textarea" || ele.type == "select"){

if ( ((ele.value == null) || (ele.value == "")) || isBlank(ele.value)){

flag = 1;

}
}
}
if (flag == 1)
{
alert("Before submitting this form,make sure the following mandatory fields are completed:"+msg);
}

}
Posted 17-Apr-13 1:10am
Comments
Member61 17-Apr-13 6:19am
   
U can use either ajax or javascript or JQuery to validate form. Check my solution. AJAX Control ...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
codegirl24 18-Apr-13 3:22am
   
I am using simple HTML code and javascript functions. But the above link is the exact scenario..I am not sure if i can resolve this problem with ASP.NET...please help
TusharKhairnar 18-Apr-13 3:51am
   
are you read that article. it gives the solution for that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160208.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100