Click here to Skip to main content
15,896,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
Rockstar_ 17-Apr-13 6:19am    
U can use either ajax or javascript or JQuery to validate form. Check my solution. AJAX Control ...

 
Share this answer
 
 
Share this answer
 
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
TrushnaK 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900