Click here to Skip to main content
16,006,006 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi gud evng,

I have two text fields as application name and date field.The id's given for those are app_name,f_date_a.My doubt is i want to keep the validations for those two fields in the script.I have already kept the code for validation as below.

C#
var app_name = document.getElementById('app_name').value;
                var date = document.getElementById('f_date_a').value;
                if(app_name==0)
                {
                    alert('Select Any One Application !!');
                    document.getElementById(app_name);
                    return false;
                }
                else if(date=='')
                {
                    alert('Date Mandatory !!');
                    document.getElementById(date);
                    return false;
                }
                else
                {
                    return true;
                }

It is displaying the alert message for application name.For date also it is displaying the message.But after clicking on the ok button it is not waiting for the date directly it is submitting.Can you give me the solution is there any thing wrong in my code.
Posted
Updated 22-Jul-11 4:26am
v2
Comments
TorstenH. 22-Jul-11 10:26am    
changed tag - it's Javascript not Java & script.

Use this on OK Button
clientclick="return yourfunctionname();"
 
Share this answer
 
Your code can't be wrong - it just doesn't meet the requirement.

You're returning to the original form and sending the data to the server - right? You need to get the return code of your message and react on that. Also you have a boolean value that is returned from your validation - that's also something you can react on.

Try to send the data only when validation returned true.
 
Share this answer
 

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