开发者

Its not validating on my submit button click using javascript

I have this code in my view

function Validate() {
   if (document.getElementById('MandateName').value == "") {

       var err = document.getElementById('MandateNameErr');
       err.innerHTML = "Please enter a value for the Mandate Name";
       err.style.display = "block";
       return false;
   }
   else {
       document.getElementById('MandateNameErr').style.display = "none";
   }

   if (document.getElementById('MandateDescription').value == "") {
       var err = document.getElementById('MandateDescriptionErr');
       err.innerHTML = "Please enter a value for the Mandate Description";
       err.style.display = "block";
       return false;
   }
   else {
       document.getElementById('MandateDescriptionErr').style.display = "none";
   }

   return true;
}

and I have on submit button I am v开发者_开发技巧alidating before submiting?

<button name="Submit" onclick="Validate()" >Add Variables to Mandate</button>

I called Validate function but its showing me if I am not entering anything on the text box if I click Button its showing me my validation message but same time its going to my view and throwing me the message?

even I put the return false; its not working is that something I am doing wrong?


You need to put return in the onclick, like this:

<button name="Submit" onclick="return Validate()" >Add Variables to Mandate</button>

Otherwise you're executing the validation...but not really caring about the result.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜