Hi EveryOne,

I am given only 2 days to finish my assignment in 2 days,but I'm only a biginner in HTML. .
I would like to ask anyone to please check if what is wrong in my code. .

<html>
<head>
<title>Lab Exercise</title>
</head>
<body>
<h2>Script Integration</h2>

<h3>Laboreatory Exercise 5 - Calculator </h3>
</br></br>

<input type="textbox" name="txtNUMBER" id="txtNUMBER"></br></br>

<input type="button" name="cmd7" Value="7" id="cmd7">
<input type="button" name="cmd8" Value="8" id="cmd8">
<input type="button" name="cmd9" Value="9" id="cmd9">
<input type="button" name="cmdADD" Value="+" id="cmdADD"></br>

<input type="button" name="cmd4" Value="4" id="cmd4">
<input type="button" name="cmd5" Value="5" id="cmd5">
<input type="button" name="cmd6" Value="6" id="cmd6">
<input type="button" name="cmdSUBTRACT" Value="-" id="cmdSUBTRACT"></br>

<input type="button" name="cmd1" Value="1" id="cmd1">
<input type="button" name="cmd2" Value="2" id="cmd2">
<input type="button" name="cmd3" Value="3" id="cmd3">
<input type="button" name="cmdMULTIPLY" Value="*" id="cmdMULTIPLY"></br>

<input type="button" name="cmd0" Value="0" id="cmd0">
<input type="button" name="cmdDOT" Value="." id="cmdDOT">
<input type="button" name="cmdEQUALS" Value="=" id="cmdEQUALS">
<input type="button" name="cmdDIVIDE" Value="/" id="cmdDIVIDE"></br>

<input type="button" name="cmdClear" Value="Clear" id="cmdClear">



</body>

<script language="vbscript">

Dim mfirst As Single
Dim msecond As Single
Dim manswer As Single
Dim mbutton As Integer
Dim Signstate As Boolean

Private Sub cmd0_onClick()

txtNUMBER = txtNUMBER + "0"
End Sub

Private Sub cmd1_onClick()

txtNUMBER = txtNUMBER + "1"
End Sub

Private Sub cmd2_onClick()

txtNUMBER = txtNUMBER + "2"
End Sub

Private Sub cmd3_onClick()

txtNUMBER = txtNUMBER + "3"
End Sub

Private Sub cmd4_onClick()

txtNUMBER = txtNUMBER + "4"
End Sub

Private Sub cmd5_onClick()

txtNUMBER = txtNUMBER + "5"
End Sub

Private Sub cmd6_onClick()

txtNUMBER = txtNUMBER + "6"
End Sub

Private Sub cmd7_onClick()

txtNUMBER = txtNUMBER + "7"
End Sub

Private Sub cmd8_onClick()

txtNUMBER = txtNUMBER + "8"
End Sub

Private Sub cmd9_onClick()

txtNUMBER = txtNUMBER + "9"
End Sub

Private Sub cmdADD_onClick()

mbutton = 1

mfirst = Val(txtNUMBER)

txtNUMBER = ""
End Sub

Private Sub cmdClear_onClick()
txtNUMBER = " "
End Sub

Private Sub cmdDIVIDE_onClick()

mbutton = 4

mfirst = Val(txtNUMBER)

txtNUMBER = ""
End Sub

Private Sub cmdDOT_onClick()
txtNUMBER = txtNUMBER + "."
End Sub

Private Sub cmdEQUALS_onClick()
msecond = Val(txtNUMBER)

Select Case mbutton
Case Is = 1
manswer = mfirst + msecond
Case Is = 2
manswer = mfirst - msecond
Case Is = 3
manswer = mfirst * msecond
Case Is = 4
manswer = mfirst / msecond
End Select
txtNUMBER = manswer
End Sub

Private Sub cmdMULTIPLY_onClick()

mbutton = 3

mfirst = Val(txtNUMBER)

txtNUMBER = ""
End Sub

Private Sub cmdSUBTRACT_onClick()

mbutton = 2

mfirst = Val(txtNUMBER)

txtNUMBER = ""
End Sub



</script>

</html>

Dani AI

Generated

Quick, practical fixes that make the buttons respond and keep the page cross‑browser: replace the invalid type="textbox" with type="text" and give the display an id (for example display); use <br> or <br/> instead of malformed break tags; set the display to disabled and text-align:right like recommended so numbers behave like a real calculator. The thread already points out the biggest portability issue — VBScript only runs in Internet Explorer — so follow and move the logic to JavaScript. (Also correct the heading spelling as noted.)

A compact, robust wiring pattern uses data attributes and a single event listener (delegation) so adding buttons is trivial. Example:

// HTML: <input id="display" type="text" disabled>
// Buttons: <button type="button" data-value="7">7</button>
// Operators: <button type="button" data-op="+">+</button>
// Clear: <button id="clear">C</button>  Equals: <button id="equals">=</button>

const display = document.getElementById('display');
let first = null, op = null;
const ops = { '+': (a,b)=>a+b, '-': (a,b)=>a-b, '*': (a,b)=>a*b, '/': (a,b)=> b===0 ? 'Error' : a/b };

document.addEventListener('click', e => {
  const btn = e.target.closest('button'); if (!btn) return;
  if (btn.dataset.value) { if (btn.dataset.value === '.' && display.value.includes('.')) return; display.value += btn.dataset.value; return; }
  if (btn.dataset.op) { first = parseFloat(display.value) || 0; op = btn.dataset.op; display.value = ''; return; }
  if (btn.id === 'equals') { const second = parseFloat(display.value) || 0; display.value = String(ops[op] ? ops[op](first, second) : second); first = op = null; return; }
  if (btn.id === 'clear') display.value = '';
});

Troubleshooting tips: place the script just before </body> or run on DOMContentLoaded; confirm element ids match; use parseFloat for decimals; clear with display.value = '' (not a single space); check the browser console for syntax errors. For better UX add keyboard handlers, aria-labels for accessibility, and button type="button" to avoid accidental form submits.

Recommended Answers

All 4 Replies

I'll tell you one thing. Heading should be:

<h3>Laboratory</h3>

</br> should be <br> for html and <br /> for xhtml. There is no such thing as </br>.

Also, why are you using vbscript? You do know vbscript only works in Internet Explorer right? Use JavaScript.

<input type="textbox" disabled='disabled' style='text-align:right;' name="txtNUMBER" id="txtNUMBER"> to make the numbers pushin from the right like a standard calc. and numbers can only be entered by keypad, not directly in the box

Thank you so much for the effort guys,but the problem is when I click the button nothing happens. .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.