Click here to Skip to main content
Rate this: bad
good
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 at 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 at 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 at 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)



Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2014
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