Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
103
rated 0 times [  105] [ 2]  / answers: 1 / hits: 24813  / 15 Years ago, tue, january 19, 2010, 12:00:00

My JavaScript function is working but for some reason after the alert is displayed inside my IF statement the page re-loads/refresh and I do not want it to. Why is this and how can I change my function so that it will not do this?



My function



function valSubmit(){    
varName = document.form1.txtName.value;
varSurname = document.form1.txtSurname.value;
varEmail = document.form1.txtEmail.value;
varOrg = document.form1.txtOrg.value;

if (varName == || varSurname == || varEmail == || varOrg == )
{

alert(Please fill in all mandatory fields);

}
else
{
document.body.style.cursor = 'wait';
document.form1.btnSubmit.style.cursor = 'wait';
document.form1.action = http://now.eloqua.com/e/f2.aspx
document.form1.submit();
return true;
}

}




p.s I am using ASP.NET 3.5


More From » javascript

 Answers
3

Here is your complete function with the return false statement added.



Additionally, when you call valSubmit, it should look like this:



... onsubmit=return valSubmit();...



Note, you need to specify return here also.



Here is the function:



function valSubmit(){

varName = document.form1.txtName.value;
varSurname = document.form1.txtSurname.value;
varEmail = document.form1.txtEmail.value;
varOrg = document.form1.txtOrg.value;

if (varName == || varSurname == || varEmail == || varOrg == )
{

alert(Please fill in all mandatory fields);
return false;

}
else
{
document.body.style.cursor = 'wait';
document.form1.btnSubmit.style.cursor = 'wait';
document.form1.action = http://now.eloqua.com/e/f2.aspx
document.form1.submit();
return true;
}

}

[#97800] Thursday, January 14, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
michaelashelbieh

Total Points: 303
Total Questions: 139
Total Answers: 97

Location: Suriname
Member since Sun, Oct 17, 2021
3 Years ago
;