ATM Machine Logic in JavaScript using ‘if’ statement.
How does this program work?
- In this program you are going to learn about how to write ATM program using ‘if’ statement.
Here is the code
<html>
<head>
<title>JavaScript program to how to write ATM program using ‘if’ statement</title>
</head>
<body>
<form method ="post">
Please Enter Your Pin Number:<input type="text" name="number" id="number" />
<input type="button" name="submit" id="submit" onclick="getaction()" value="go"/>
<p id="demo"> </p>
<div id="options12" style="display:none;">
<input type='radio' name='radio' onclick='myfunction(this.value)' value='1'/>Balance
<input type='radio' name='radio' onclick='myfunction(this.value)' value='2'/>Withdraw
<input type='radio' name='radio' onclick='myfunction(this.value)' value='3'/>Fastcash
</div>
<p id="demo1",></p>
<div id="display" style="display:none;">
<label>Please Enter Your Withdraw Amount</label>
<input type="text" name="amount1" id="amount1" value=""/>
<input type="submit" name="submit1" value="submit" onclick="getamount()"/>
</div>
<div id="display1" style="display:none;">
<label>Please Select Your Fastcash Option</label>
<select id="myselect1">
<option value="10000">10000</option>
<option value ="20000">20000</option>
< option value ="50000">50000</option>
</select>
<input type="submit" name="submit2" value="submit" onclick="getamount1()">
</div>
</form>
</body>
<script type="text/javascript">
function getaction()
{
//Intialise Pin value with varible P
var p = document.getElementById ('number').value;
var a = 1234;
//To check Pin entered is correct or not
if(p==a)
{
document.getElementById ("demo").innerHTML ="Please Choose transcation";
document.getElementById ('options12'). style.display = 'block'; //if pin number is correct options will Display.
}
else
{
document.getElementById ("demo").innerHTML = "Invalid pin";
}
}
function myfunction(val)
{
//function to display balance amount
m = 10000;
if(val==1)//Option 1 is select to shows balance amount
{
document.getElementById ('demo1' ).innerHTML ="Your amount is: "+m;
document.getElementById ('display' ). style.display = 'none';
document.getElementById ('display1' ). style.display = 'none';
}
if(val==2)//Option 2 select to display text field to enter withdraw amount
{
document.getElementById ('display').style.display = 'block';
document.getElementById ('display1').style.display = 'none';
}
if(val==3)//Option 3 is select to display fastcash option
{
document.getElementById ('display1').style.display = 'block';
document.getElementById ('display').style.display = 'none';
}
}
function getamount()
{
//function To Withdraw Amount
m = 10000;
//Intialise the textbox value in a varible
var a = document.getElementById ('amount1' ).value;
//Check if entered amount is greater than the original amount or not and it also should be mulitple of 100
if(a<=m&&a%100==0)
//alert("" +a);
document.getElementById ('display').innerHTML ="Your withdraw amount : "+a;
else
//alert("invalid cash");
document.getElementById ('display').innerHTML ="Invalid cash";
}
function getamount1()
{
//Intialise the Dropdown value in a varible
var x = document.getElementById ("myselect1").value
m = 10000;
//check if selected amount is greater than the original amount or not and it should be mulitple of 100
if(x<=m&&x%100==0)
//alert("take your amount" +x);
document.getElementById ('display1').innerHTML ="Please take your amount : "+x;
else
document.getElementById ('display1').innerHTML ="Invalid cash";
}
</script>
</html>