Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
2.40/5 (2 votes)
I am Performing Calculation of Student fee Details,There are Two Text boxes,one which is automatically fixed(disabled)as Rs.5000,If i enter value below Rs.5000 value on another Text box then it will calculate subtraction and show balance in result text box.If i enter value above Rs.5000 it should not take that value in second text box.I want to validate text box depending on first text box value.
Posted
Comments
Sergey Alexandrovich Kryukov 16-Nov-15 2:31am    
The worst thing you have done is: you included executable (PE) files. Not only they take storage and consume traffic, having them is simply unsafe. You should publish only pure source code.

Now, what's the problem? Validate your value based on another text box, why not? (It does not seem to be the best UI design, but this is a different story.)

—SA

C#
function calc() {       
        var x = trim(document.getElementById("<%=txtFirst.ClientID%>").value);
        var y = trim(document.getElementById("<%=txtSecond.ClientID%>").value);
        if (parseInt(y) > parseInt(x)) {
            alert("Less than 5000 is allow");
            document.getElementById("<%=txtSecond.ClientID%>").value = "";
            document.getElementById("<%=txtSecond.ClientID%>").focus();
            return false;
        }
        else
        {
           var Remaining = parseInt(x) - parseInt(y)
           document.getElementById("<%=txtResult.ClientID%>").value = Remaining ;
        }
        return true;
    }

and on your second text box  call function when text box is blur

 <asp:textbox id="txtSecond" runat="server" onblur="calc()" xmlns:asp="#unknown">   </asp:textbox>  
 
Share this answer
 
Try
C#
$("textbox2id").focusOut(function(){
  if(!($("textbox2id").val() >= "5000"))
    {
      //Do stuff
      $(this).focus();
    }
})
 
Share this answer
 
Your first textbox doesn't matter if you're disabling it. So do something like-
JavaScript
$("#secondtxt").keyup(function(){
    var val = $(this).val(), result = 0;
    if(val < 5000){
        result = 5000 - val;  // calculate subtraction 
    }
    else if(val > 5000){
        result = "";
        $(this).val(''); // should not take that value
    }
    
    $("#resultTxt").val(result);
});

Pretty simple, eh ?

-KR
 
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