Click here to Skip to main content
15,900,511 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a MVC view in which I am using

C#
@using (Html.BeginForm(ProductdetailSave,Product_Catalog, FormMethod.Post))


I have two textboxes MRP and selling price . I want to validate selling price should not be greater than MRP . so I using on click- "checkSP()".
It is executing function but though it is returning false, my form gets submitted

What I have tried:

JavaScript
function checkSP()
{
    debugger;

    var MRP = $("#MRP").val();
    var SP = $("#Selling_price").val();

    if (parseInt(MRP) < parseInt(SP)) {
        alert("Selling Price Should be Less Than MRP");

        return false;
    }

}
Posted
Updated 30-Mar-16 3:17am
v2
Comments
Karthik_Mahalingam 29-Mar-16 4:01am    
post your form code.

You can use onclick="return checkSP()"

When you call a method (that return value) on an onclick event then put return before that method, because your method will return value (either true/false).

Thanks,
 
Share this answer
 
Comments
Karthik_Mahalingam 29-Mar-16 4:03am    
yes, you are right.
After the return false, the event is propagating through. You can try e.preventDefault() as well.
And one more thing is on tab out of the selling price itself have the function check using onfocusout event, rather than doing that on submit. That will alert user before filling in other values as well.

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900