Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old October 26th, 2005, 08:44 AM
roggel roggel is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: The Netherlands
Posts: 9 roggel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 40 sec
Reputation Power: 0
Have two text fields react to each other

Hi there,

I'm building a stock market game, where children can buy and sell shares in virtual companies.
At some point I want them to be able to buy shares, obviously. On the buy page there should be two textfields, A and B.
The children can now decide to type in the NUMBER of shares they want to buy in textfield A. When they press Tab or Enter, textfield B should automatically update to the amount of dollars they should pay for it (number of shares * value of 1 share).
But they should also be able to type in the amount of dollars they want to spend in textfield B, which would automatically update textfield A to the number of shares they'd get for that amount of money.

Can this be done using PHP? (I guess not, but I thought I should ask). Should this be done in JavaScript and if so, how? (Complete Javascript newbie)...

Reply With Quote
  #2  
Old October 28th, 2005, 03:48 AM
brut brut is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 367 brut User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 30 sec
Reputation Power: 2
RE: Have two text fields react to each other

Something like this should get you started:
php Code:
Original - php Code
  1.  
  2.   <script language="javascript">
  3.       function update(obj){
  4.          stockPrice=document.getElementById('stock').option  s[document.getElementById('stock').selectedIndex].value;
  5.          if(obj.id=="shares"){
  6.             document.getElementById('cost').value=obj.value*st  ockPrice;
  7.          }else{
  8.             document.getElementById('shares').value=obj.value/stockPrice;
  9.          }
  10.       }
  11.   </script>
  12.  
  13.   <select name="stock" id="stock">
  14.    <option value="47.4">DIS</option>
  15.    <option value="82.1">TWX</option>
  16.    <option value="49.3">VIA-B</option>
  17.    <option value="47.4">NWS-A</option>
  18.   </select>
  19.   <br />
  20.   Shares:<input type="text> name="shares" id="shares" onchange="update(this);">
  21.   <br />
  22.   Cost:<input type="text> name="cost" id="cost" onchange="update(this);">

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > Have two text fields react to each other


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway