Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.


javascript ?

  • Please log in to reply
1 reply to this topic

#1 12Strings


  • Members
  • 41 posts
  • Local time:11:13 PM

Posted 22 September 2014 - 06:19 PM

Hi, I don't attempt much JS. The following code is to display calculator results.
How do I show which operator was entered? All else is fine.

   <script language="javascript" 
multiply(){ a=Number(document.calculator.first.value); b=Number(document.calculator.second.value); c=a*b; document.calculator.total.value=c; 
} </script> <script language="javascript" 
type="text/javascript"> function 
addition(){ a=Number(document.calculator.first.value);b=Number(document.calculator.second.value); c=a+b; document.calculator.total.value=c; 
} </script> <script language="javascript" 
type="text/javascript"> function 
subtraction(){ a=Number(document.calculator.first.value); b=Number(document.calculator.second.value); c=a-b; document.calculator.total.value=c; 
} </script> <script language="javascript" 
type="text/javascript"> function 
division(){ a=Number(document.calculator.first.value); b=Number(document.calculator.second.value); c=a/b; document.calculator.total.value=c; 
} </script>  </head>  <body>  <form 
name="calculator" action=""  method="post"><input type="text" 
name="item" size=25 onFocus="this.value=''" 
value="item"><br>      <!-- enter 
1st value. --><input type="text" name="first" size=6 
value="value1">     <!-- enter 2nd value. 
--><input type="text" name="second" size=6 onFocus="this.value=''" 
value="value2">       <!-- Here 
respective button when clicked, calls only respective artimetic function. 
-->  <input type="button" name="operator" value="+" 
onclick="javascript:addition();"> <input type="button" 
name="operator" value="-" 
onclick="javascript:subtraction();"> <input type="button" 
name="operator" value="x" 
onclick="javascript:multiply();"> <input type="button" 
name="operator" value="/" onclick="javascript:division();"> <!-- 
Here is result  -->  = <input type="text" name="total" 
size=6 onFocus="this.value=''" 
value="sum"><br><br>     <input 
type="submit" name="submit" value="include 
data"><br><br>       </form>

BC AdBot (Login to Remove)


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer

  • Malware Response Team
  • 12,304 posts
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:09:13 PM

Posted 22 September 2014 - 09:21 PM

  1. Looks like your code box is messed up :)
  2. You can show the entered operator the same way you'd show any other content -- by setting InnerHTML or doing DOM manipulation on the actual page.


Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users