JavaScript formname.submit() problem.

I wonder if anybody has come across this problem before...

I have a page with a form, when this is submitted, it is "Error checked"..

If everything is filled in correctly then the form should be submitted, however, when the the form is submitted, I get an error saying "Error: Access is Denied Code:0".

The code used is below....

function valcheckdate(objName,formname){

if (checkdate(objName) == true) {

error = 0;

if (formname.CheckRef.value != "VS"+vscodecss+vscodedd+vscodemm+vscodeyy) error = 1;

if (formname.CheckersName.value.length < 4) error = 3;

if (formname.CheckersName.value == "FM Name") error = 5;

if (error == 1){

formname.CheckRef.value = "VS"+vscodecss+vscodedd+vscodemm+vscodeyy;

alert ("Check Ref has been reset and can not been changed");

}

if (error == 3) alert ("Checkers Name must be entered");

if (error == 5) alert ("You must Change Checkers Name to Your Name");

if (error == 0) formname.submit() ;

Everything works up to the formname.submit(), I have proved this by changing the submit to an alert box which works fine...

Andy ideas???

#485077

Okay, i hope i interpret your problem the right way.

Try it like this:

The form

<form action="action" method="POST" name="formname" onsubmit="return valcheckdate(xxx, yyy)">
whatever theres in the form
</form>

The java script:

function valcheckdate(objName,formname) {
if (checkdate(objName) == true) {
error = 0;
if (formname.CheckRef.value != "VS"+vscodecss+vscodedd+vscodemm+vscodeyy) error = 1;
if (formname.CheckersName.value.length < 4) error = 3;
if (formname.CheckersName.value == "FM Name") error = 5;
if (error == 1) {
formname.CheckRef.value = "VS"+vscodecss+vscodedd+vscodemm+vscodeyy;
alert ("Check Ref has been reset and can not been changed");
return false;
}
if (error == 3) {
alert ("Checkers Name must be entered");
return false;
}
if (error == 5) {
alert ("You must Change Checkers Name to Your Name");
return false;
}
return true;
}
}

The form is only submitted when there are no errors (return true; )

Hope it works for you this way

#485078

You shouldn't use formname.submit(), as it may trigger the validation (depending on the browser) (which in turn will do a formname.submit(), which will trigger... I hope you understand now).

I was about to suggest another way to do, but it is exactly the way schmrom suggested :).

#485130