473,378 Members | 1,138 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

validation problems

Hello

I have been working on this for quite some time now, and have no clue
why my app behaves the way it does.
Here is the code snippet that controls this behaviour.
/////////////////////////////////////////////////////////////////////////////////////
function validateForm()
{
var valid = true;
var today = new Date();
var curdate = today.getFullYear()+"-"+(today.getMonth()
+1)+"-"+today.getDate();
if (compareDates(curdate,"yyyy-M-
d",document.Parms.ENDDATE.value,"yyyy-MM-d") != 0)
{
alert ("blah blah .");
valid = false;
}
return valid;
}
function submitForm(clickbutton)
{
if (clickbutton.name == "submit")
{
if (validateForm())
{
//blah blah
document.top.action = "./task_submitrecord.jsp";
document.Parms.action = "./task_submitrecord.jsp";
document.top.submit();
document.Parms.submit();
}
}
else if (clickbutton.name == "cancel")
{
document.top.action = "./task_init.jsp";
document.Parms.action = "./task_init.jsp";
document.top.submit();
document.Parms.submit();
}

}
/////////////////////////////////////////////////////////////////////////////////////

I have two forms on this page: top and Parms and I intend to submit
them after a validation function has worked its way through to
ensuring all values are the way I want them to be. My validation
function works fine and displays the alert messages as I want them. I
check for the valid variable in the submitForm function and only do
the submit action after validation has returned true! Although I see
the error messages which guarantees that valid has been set to false,
why does my page refresh at all? It does not go to the next page, but
it refreshes the same page and loses half the interface information.
If all the information is correct and no error messages are found,
then the new link is opened and the functionality is completed. But if
validation results in an error, then the same page keeps refreshing
itself (I hope this is clear enough).
I can press the back button to restore the page (which could be a
workaround for this case), but I would like to know what exactly is
screwing this up? Is it the multiple forms being submitted together or
is it something else? Thanks in advance.

Jun 5 '07 #1
2 1463
On Jun 5, 10:26 am, Gobind <gobind.jo...@gmail.comwrote:
Hello

I have been working on this for quite some time now, and have no clue
why my app behaves the way it does.
Here is the code snippet that controls this behaviour.
/////////////////////////////////////////////////////////////////////////////////////
function validateForm()
{
var valid = true;
var today = new Date();
var curdate = today.getFullYear()+"-"+(today.getMonth()
+1)+"-"+today.getDate();
if (compareDates(curdate,"yyyy-M-
d",document.Parms.ENDDATE.value,"yyyy-MM-d") != 0)
{
alert ("blah blah .");
valid = false;
}
return valid;

}

function submitForm(clickbutton)
{
if (clickbutton.name == "submit")
{
if (validateForm())
{
//blah blah
document.top.action = "./task_submitrecord.jsp";
document.Parms.action = "./task_submitrecord.jsp";
document.top.submit();
document.Parms.submit();
}
}
else if (clickbutton.name == "cancel")
{
document.top.action = "./task_init.jsp";
document.Parms.action = "./task_init.jsp";
document.top.submit();
document.Parms.submit();
}

}

/////////////////////////////////////////////////////////////////////////////////////

I have two forms on this page: top and Parms and I intend to submit
them after a validation function has worked its way through to
ensuring all values are the way I want them to be. My validation
function works fine and displays the alert messages as I want them. I
check for the valid variable in the submitForm function and only do
the submit action after validation has returned true! Although I see
the error messages which guarantees that valid has been set to false,
why does my page refresh at all? It does not go to the next page, but
it refreshes the same page and loses half the interface information.
If all the information is correct and no error messages are found,
then the new link is opened and the functionality is completed. But if
validation results in an error, then the same page keeps refreshing
itself (I hope this is clear enough).
I can press the back button to restore the page (which could be a
workaround for this case), but I would like to know what exactly is
screwing this up? Is it the multiple forms being submitted together or
is it something else? Thanks in advance.
Never mind....I solved it! (turns out declaring your buttons as input
type submits causes a double submit action and forces a refresh if
nothing else, changed those to regular buttons and it worked)

Jun 5 '07 #2
Lee
Gobind said:
>
Hello

I have been working on this for quite some time now, and have no clue
why my app behaves the way it does.
Here is the code snippet that controls this behaviour.
/////////////////////////////////////////////////////////////////////////////////////
function validateForm()
{
var valid = true;
var today = new Date();
var curdate = today.getFullYear()+"-"+(today.getMonth()
+1)+"-"+today.getDate();
if (compareDates(curdate,"yyyy-M-
d",document.Parms.ENDDATE.value,"yyyy-MM-d") != 0)
{
alert ("blah blah .");
valid = false;
}
return valid;
}
function submitForm(clickbutton)
{
if (clickbutton.name == "submit")
{
if (validateForm())
{
//blah blah
document.top.action = "./task_submitrecord.jsp";
document.Parms.action = "./task_submitrecord.jsp";
document.top.submit();
document.Parms.submit();
}
}
else if (clickbutton.name == "cancel")
{
document.top.action = "./task_init.jsp";
document.Parms.action = "./task_init.jsp";
document.top.submit();
document.Parms.submit();
}

}
/////////////////////////////////////////////////////////////////////////////////////

I have two forms on this page: top and Parms and I intend to submit
them after a validation function has worked its way through to
ensuring all values are the way I want them to be. My validation
function works fine and displays the alert messages as I want them. I
check for the valid variable in the submitForm function and only do
the submit action after validation has returned true! Although I see
the error messages which guarantees that valid has been set to false,
why does my page refresh at all?
The problem is probably in the HTML code. If you're using the
onClick event handler of a link, but not intending to actually
link to anything, that's probably at the root of your problem.
What you see as a page refresh is the browser following the link
to the current page.

In general, it's a bad idea to submit a form via Javascript in
a validation function. Use a type=submit button and have your
onsubmit event handler return false if your validation fails.
--

Jun 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
3
by: arc | last post by:
I have a server object that performs zipcode validation based on zipcode entered in the web form. Ideally this should work as follows: Once the zip code is entered in the edit box it should...
0
by: Brian Conway | last post by:
I am having some validation and insertion problems. I am using a date picker that takes the selected date and puts it to ("dd-MMM-yyyy") format, as this was the only format that Oracle would...
3
by: arc | last post by:
I have a server object that performs zipcode validation based on zipcode entered in the web form. Ideally this should work as follows: Once the zip code is entered in the edit box it should...
1
by: Simon | last post by:
Hi, Has anyone experienced the problem where validation controls stop a previously working page from submitting. Sometimes, when I move between my work machine and my home machine validation...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.