validation problems

G

Gobind

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.
 
G

Gobind

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)
 
L

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.


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,160
Messages
2,570,890
Members
47,423
Latest member
henerygril

Latest Threads

Top