Hello ,
I am working in javascript and i want to validate some field.
If condtion fail then return to main page?
Please define how to return main page if validation fail in javascript?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Abrar Ahmad AnsariRank #3,390 · 425 reputationPosted Apr 20, 2015, 2:09 AM EDT
Davin MartynRank #285 · 8.8K reputationPosted Apr 20, 2015, 2:38 AM EDT
if(var== null)
{
alert ("");//some message
window.location.href = 'mainpage.asp';
} else
{
return true;
}
}
this is right or wrong
Abrar Ahmad AnsariRank #3,390 · 425 reputationPosted Apr 20, 2015, 2:46 AM EDT
var obj = null;
if(obj== null)
{
alert ("");//some message
window.location.href = 'mainpage.asp';
}
else { return true; }
Davin MartynRank #285 · 8.8K reputationPosted Apr 20, 2015, 3:06 AM EDT
{
var e1 = document.getElementById('txtEmail');
var e2 = document.getElementById('txtDISPLAY');
if(e1 ==null)
{
alert('Return value of gEBI: ' + e2.value);
window.location.href ='LetterWorksheet.asp';
}
else
{
return true;
}
} this is my function but this is redirect next page
Abrar Ahmad AnsariRank #3,390 · 425 reputationPosted Apr 20, 2015, 3:25 AM EDT
//use below code.
function checkValues(MyForm) {
var e1 = document.getElementById("<%=txtEmail.ClientID%>").value;
var e2 = document.getElementByI("<%=txtDISPLAY.ClientID%>").value;
if (e1 == "" || e2 == "") {
alert('Return value of gEBI: ' + e2.value);
window.location.href = 'LetterWorksheet.asp';
}
else {
return true;
}
}
Davin MartynRank #285 · 8.8K reputationPosted Apr 20, 2015, 4:18 AM EDT
Abrar Ahmad AnsariRank #3,390 · 425 reputationPosted Apr 23, 2015, 2:41 AM EDT
suppose you have defined your function
function formvalue()
{
var MyForm=get myfrom ;
return checkValues(MyForm);
}