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 March 8th, 2005, 04:51 PM
mikenco mikenco is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: UK
Posts: 62 mikenco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
A simple puzzle?

Can anyone create the javascript to make this work?
(It uses onCLick and onCHange rather than submitting to a server side program)

php Code:
Original - php Code
  1.  
  2. <html>
  3. <head>
  4. <title>Who Owes What?</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. </head>
  7.  
  8. <body>
  9. <form name="cif" method="post" action="">
  10.   <p> 1st debt belongs to:
  11.     <select name="select1" id="select1">
  12.       <option value="person_a">Person A</option>
  13.       <option value="person_b">Person B</option>
  14.     </select>
  15.     and is worth:
  16.     <input name="debt_row1" type="text" id="debt_row1" value="0" onChange="docalcs()">
  17.   </p>
  18.   <p> 2nd debt belongs to:
  19.     <select name="select2" id="select4">
  20.       <option value="person_a">Person A</option>
  21.       <option value="person_b">Person B</option>
  22.     </select>
  23.     and is worth:
  24.     <input name="debt_row2" type="text" id="debt_row2" value="0" onChange="docalcs()">
  25.   </p>
  26.   <p>3rd debt belongs to:
  27.     <select name="select3" id="select5">
  28.       <option value="person_a">Person A</option>
  29.       <option value="person_b">Person B</option>
  30.     </select>
  31.     and is worth:
  32.     <input name="debt_row3" type="text" id="debt_row3" value="0" onChange="docalcs()">
  33.   </p>
  34.   <hr>
  35.   <p>Summary:</p>
  36.   <p>
  37.     <input type="button" name="Button" value="Calculate Summary" onClick = "docalcs()">
  38.   </p>
  39.   <p>"Person A total debts" =
  40.     <input name="personA_debts" type="text" id="personA_debts" value="0">
  41.     <br>
  42.     "Person B total debts" =
  43.     <input name="personB_debts" type="text" id="personB_debts" value="0">
  44.   </p>
  45. </form>
  46. </body>
  47. </html>


If you can, it would help me solve a much larger problem and I would be eternally grateful!

Reply With Quote
  #2  
Old March 8th, 2005, 05:59 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: A simple puzzle?

you never posted the code for the doCalcs() function which would be necessary to figure out yor problem.

Reply With Quote
  #3  
Old March 8th, 2005, 06:19 PM
mikenco mikenco is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: UK
Posts: 62 mikenco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: A simple puzzle?

I didn't have one when I posted that, I have been posting more complicated versions here, but no one replied.

However, after writing the simple form, it came clear and here is the .js (Although, it'd be intresting to see how it should be written properly!):

php Code:
Original - php Code
  1.  
  2. function docalcs(){
  3. // "Outgoings Summary"  (ensure corrections are cleared)
  4.  
  5.     document.cif.personA_debts.value = 0
  6.     document.cif.personB_debts.value = 0
  7.  
  8.     var a = (document.cif.personA_debts.value*1);
  9.     var b = (document.cif.personB_debts.value*1);
  10.  
  11. // "Outgoings Summary" ----------------- ROW ONE
  12. if (document.cif.select1.selectedIndex==1) {
  13.     //(personA)
  14.     var os1 = (document.cif.debt_row1.value-0);
  15.     document.cif.personA_debts.value = (a+=os1);
  16.     }
  17.  
  18. if (document.cif.select1.selectedIndex==2) {
  19.     //(personB)
  20.     var os2 = (document.cif.debt_row1.value-0);
  21.     document.cif.personB_debts.value = (b+=os2);
  22.     }
  23.  
  24. // "Outgoings Summary" ----------------- ROW TWO
  25. if (document.cif.select2.selectedIndex==1) {
  26.     //(personA)
  27.     var os3 = (document.cif.debt_row2.value-0);
  28.     document.cif.personA_debts.value = (a+=os3);
  29.     }
  30.  
  31. if (document.cif.select2.selectedIndex==2) {
  32.     //(personB)
  33.     var os4 = (document.cif.debt_row2.value-0);
  34.     document.cif.personB_debts.value = (b+=os4);
  35.     }
  36.  
  37. // "Outgoings Summary" ----------------- ROW THREE
  38. if (document.cif.select3.selectedIndex==1) {
  39.     //(personA)
  40.     var os5 = (document.cif.debt_row3.value-0);
  41.     document.cif.personA_debts.value = (a+=os5);
  42.     }
  43.  
  44. if (document.cif.select3.selectedIndex==2) {
  45.     //(personB)
  46.     var os6 = (document.cif.debt_row3.value-0);
  47.     document.cif.personB_debts.value = (b+=os6);
  48.     }
  49. }

Reply With Quote
  #4  
Old March 8th, 2005, 06:23 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: A simple puzzle?

can you give a little more background on what is to happen as each dropdown is changed?

Reply With Quote
  #5  
Old March 8th, 2005, 06:34 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: A simple puzzle?

FYI the onChange event fires as the textbox loses focus, not as the text is changed. The code as you have it seems to work fine.

another problem is that selectedIndex starts at 0 not 1

Reply With Quote
  #6  
Old March 8th, 2005, 06:43 PM
mikenco mikenco is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: UK
Posts: 62 mikenco User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: A simple puzzle?

Yes, the SelectedIndex does, but zero is current a line that says "Choose" (I may add an alert to this Index)

The main form that I am working on is here :

http://www.mikenco.com/generalcif-temp.html

If you want to see the bit to which this applies, scroll down the page to the smaller of the two large tables enititled "Any other debts, including loans, credit cards, store cards etc"

Choose "self" from the first column, add a value to the pink column, then scroll down the page to the section marked "Outgoings Summary".

As you can see I have much to do yet!!.. as well as write the PHP processor for emailing the form (but that bit I have done before and is not too hard)

Please don't spend any valuable time on this unless you are bored as I have resolved the issue which I was having trouble with.

(If you can see any other potentially better ways of doing anything in the form, I would surely appreciate the input)

Thanks for your intrest

Mike


Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > A simple puzzle?


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 3 hosted by Hostway