Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Client Side Scripting
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 10-16-2009, 08:37 PM
  #1
evajs
Novice (Level 1)
 
Join Date: Oct 2009
Posts: 6
iTrader: (0)
evajs is an unknown quantity at this point
calculations real-time in html

Hi Experts!

I have a very clear idea of what I want my html/JavaScript to do, but absolutely no idea how to accomplish it... so I'm really counting on your help!

Here is the challenge: I have two text boxes. I want people to be able to type numbers in the first box, and while they type in the first box, I need the second box to immediately display the same number typed in the first box, but multiplied by 4. Is it possible to write a code that would perform such calculation in real-time?

I'd greatly appreciate your help!
evajs is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-17-2009, 08:59 AM
  #2
coothead
~ bald headed old fart ~
 
coothead's Avatar
 
Join Date: Aug 2003
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 7,922
iTrader: (0)
coothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to behold
Hi there evajs,

and a warm welcome to these forums.

Here is a very basic example for you to try...
Code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english"> 
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title></title>

<script type="text/javascript">
if(window.addEventListener){
   window.addEventListener('load',multiplication,false);
 }
else { 
if(window.attachEvent){
   window.attachEvent('onload',multiplication);
  }
 }

function multiplication(){

/* this value may be edited */

   multiplier=4;

/****************************/

   document.getElementById('m').firstChild.nodeValue='number x '+multiplier+' : ';
   document.getElementById('in').onkeyup=function() {
if(isNaN(this.value)) {
   alert('Come on, this is not rocket science!!!\n\nJust numbers please.')
   this.value='';
   document.getElementById('out').value=0;
   return;
 }
else {
   document.getElementById('out').value=this.value*multiplier;
   }
  }
 }
</script>

</head>
<body>

<div>
<label for="in">enter number : </label><input id="in" type="text">
<label id="m" for="out">&nbsp;</label><input id="out" type="text" value="0" readonly="readonly">
</div>

</body>
</html>
__________________

Last edited by coothead : 10-17-2009 at 09:08 AM. Reason: Typing error as per usual
coothead is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-27-2009, 02:25 PM
  #3
evajs
Novice (Level 1)
 
Join Date: Oct 2009
Posts: 6
iTrader: (0)
evajs is an unknown quantity at this point
This code does EXACTLY what I needed it to do! Thanks!

Hi coothead! not sure what the etiquette for these forums is for the 'thank you notes' i read somewhere it's inappropriate to "waste space" with Thank Yous. But I'm just so grateful for your help, so... THANKS so much!! the code does exactly what I need it to do and works so smoothly! I would never have been able to figure it out myself.

I greatly appreciate your help!
evajs
evajs is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 10-27-2009, 02:40 PM
  #4
coothead
~ bald headed old fart ~
 
coothead's Avatar
 
Join Date: Aug 2003
Location: chertsey, a small town 25 miles south west of london, england.
Posts: 7,922
iTrader: (0)
coothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to beholdcoothead is a splendid one to behold
No problem, you're very welcome.
__________________
coothead is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote

Reply
KEEP TABS
SPONSORS
 
Boxedart
 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 05:40 PM.

   

Mascot team created by Drawshop.com

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.