im trying to create a calculator that adds divides and multiplies either decimal or binary input. i have worked out the 2 functions to do this but i dont know how to call the functions using a pull down menu so when i click calculate it uses the appropriate function.
i have pasted the code down below any help would be great
i have pasted the code down below any help would be great
Code:
<html>
<head>
<script type="text/javascript">
function dec(a,b,c)
{
var a;
var b;
var c;
var answer;
a = parseInt(a, 10)
// b = parseInt(b, 10)
c = parseInt(c, 10)
if (b=="+")
{
answer = a + c
document.write(answer)
}
else if (b=="*")
{
answer = a * c
document.write(answer)
}
else
{
answer = a / c
document.write(answer)
}
}
</script>
<script type="text/javascript">
function bin(a,b,c)
{
var a;
var b;
var c;
var answer;
a = parseInt(a, 2)
// b = parseInt(b, 2)
c = parseInt(c, 2)
if (b=="+")
{
answer = a + c
document.write(answer.toString(10))
}
else if (b=="*")
{
answer = a * c
document.write(answer.toString(10))
}
else
{
answer = a / c
document.write(answer.toString(10))
}
}
</script>
</head>
<body>
<form>
<input type="text" name="a" size="2">
<p>
<input type="text" name="b" size="2">
<select name="ab">
<option value=""></option>
<option value="dec">Decimal</option>
<option value="bin">Binary</option>
</select>
</p>
<p>
<input type="text" name="c" size="2">
</p>
<p>
<input type="button" value="Calculate" onclick="(a.value, b.value, c.value)">
</p>
</form>
</body>
</html>
Comment