Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Javascript Hello, I can\'t seem to get the reset button to work, can someone hel

ID: 3865180 • Letter: J

Question

Javascript Hello, I can't seem to get the reset button to work, can someone help me get it working?

Also how would I place an alert box declining a withdrawal amount that is more than the current balance?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs" Inherits="Default6" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Lab1</title>
</head>
<body>
    <script>
        function DoMath()
        {
            var y = parseFloat(document.getElementById('Result').value);
            var x = parseFloat(document.getElementById('Transaction').value);
            if (document.getElementById('Deposit').checked == true)
                document.getElementById('Result').value = (y + x).toFixed(2).toString();
            if (document.getElementById('Withdrawal').checked == true)
                document.getElementById('Result').value = (y - x).toFixed(2).toString();
            if (document.getElementById('ServiceCharge').checked == true)
                document.getElementById('Result').value = (y - x).toFixed(2).toString();
        }
        </script>
    <script>
        function funClear() {
            document.getElementById("Transaction").reset();
            document.getElementById("Withdrawal").reset();
            document.getElementById("Deposit").reset();
            document.getElementById("ServiceCharge").reset();
            }
    </script>
    <form id="myform" runat="server">
    <div>
     <center><p><asp:Image ID="Image1" runat="server" ImageUrl="~/banklogo (1).png" /></p>
        <asp:RadioButton ID="Withdrawal" runat="server" GroupName="Banking" /> Withdrawal
        <asp:RadioButton ID="Deposit" runat="server" GroupName="Banking" /> Deposit
         <asp:RadioButton ID="ServiceCharge" runat="server" GroupName="Banking" /> Service Charge
        <p><asp:TextBox ID="Transaction" runat="server"></asp:TextBox>Transaction</p>
       <p><asp:Button ID="computeb" runat="server" Text="Compute" /></p>
        <p><asp:TextBox ID="Result" runat="server">0</asp:TextBox>Current Balance</p>
        <p><asp:Button ID="Reset" runat="server" Text="Reset"></asp:Button></p></center>
    </div>
    </form>
</body>

Explanation / Answer

Modified the folloiwng lines of code to make it work:

Reset the values.

1) Reset button was not calling funClear() function. Hence changed it:

<p><asp:Button ID="Reset" runat="server" Text="Reset" OnClientClick="funClear();"></asp:Button></p></center>

2) Changed the funClear function for the appropriate command for resetting the text box and radio button as reset command does not works in all cases.

function funClear() {
document.getElementById("Transaction").value = "";
document.getElementById("Withdrawal").checked = false;
document.getElementById("Deposit").checked = false;
document.getElementById("ServiceCharge").checked = false;
}

Place an alert box declining a withdrawal amount that is more than the current balance?

It is not clearly mentioned when to take this action,hence per the assumption on click of Compute button this validation has been placed. It can be changed to required place but the logic will remain same.

function DoMath() {
var y = parseFloat(document.getElementById('Result').value);
var x = parseFloat(document.getElementById('Transaction').value);
if (document.getElementById('Deposit').checked == true)
document.getElementById('Result').value = (y + x).toFixed(2).toString();
if (document.getElementById('Withdrawal').checked == true)
{
if (x > document.getElementById('Result').value)
alert("Withdrawl amount cannot be more than the current balance ")
else
document.getElementById('Result').value = (y - x).toFixed(2).toString();
}
if (document.getElementById('ServiceCharge').checked == true)
document.getElementById('Result').value = (y - x).toFixed(2).toString();   
}

Complete Code

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Lab1</title>
</head>
<body>   
<script>
function DoMath() {
var y = parseFloat(document.getElementById('Result').value);
var x = parseFloat(document.getElementById('Transaction').value);
if (document.getElementById('Deposit').checked == true)
document.getElementById('Result').value = (y + x).toFixed(2).toString();
if (document.getElementById('Withdrawal').checked == true)
{
if (x > document.getElementById('Result').value)
alert("Withdrawl amount cannot be more than the current balance ")
else
document.getElementById('Result').value = (y - x).toFixed(2).toString();
}
if (document.getElementById('ServiceCharge').checked == true)
document.getElementById('Result').value = (y - x).toFixed(2).toString();   
}
</script>
<script>
function funClear() {
document.getElementById("Transaction").value = "";
document.getElementById("Withdrawal").checked = false;
document.getElementById("Deposit").checked = false;
document.getElementById("ServiceCharge").checked = false;
}
</script>
<form id="myform" runat="server">
<div>
<center><p><asp:Image ID="Image1" runat="server" ImageUrl="~/banklogo (1).png" /></p>
<asp:RadioButton ID="Withdrawal" runat="server" GroupName="Banking" /> Withdrawal
<asp:RadioButton ID="Deposit" runat="server" GroupName="Banking" /> Deposit
<asp:RadioButton ID="ServiceCharge" runat="server" GroupName="Banking" /> Service Charge
<p><asp:TextBox ID="Transaction" runat="server"></asp:TextBox>Transaction</p>
<p><asp:Button ID="computeb" runat="server" Text="Compute" /></p>
<p><asp:TextBox ID="Result" runat="server">0</asp:TextBox>Current Balance</p>
<p><asp:Button ID="Reset" runat="server" Text="Reset"></asp:Button></p></center>
</div>
</form>
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote