Course Banner


Function with argument

this type of function is usually used when you want to call function and pass value into function argument while calling the function. The value will be dynamic. Write code once and use anywhere, save time.
Example :
<script>
function calculateSalary(salary,totalDays){
alert(salary);
var perDay=salary/30;
var netSalary = totalDays*perDay;
//document.write(netSalary);
document.getElementById('result').innerHTML="<strong>Your Salary is : "+ salary + " And your net salary is: "+netSalary+"</strong>";
}
</script>
<html>
<head>
<title> Calculate salary</title>
</head>
<body>
<div id="result"><h2>Calculate Salary</h2></div>
<table>
<tr>
<td>Enter Salary : </td>
<td><input type="text" name="salary" id="salary"></td>
</tr>
<tr>
<td>Enter Total Days : </td>
<td><input type="text" name="days" id="days"></td>
</tr>
<tr>
<td> </td>
<td>
<input type="button" name="button" value="CalculateSalary1"
onclick="calculateSalary(document.getElementById('salary').value,document.getElementById('days').value);"></td>
</tr>
</table>
</body>
</html>