473,486 Members | 2,340 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trigger financial calculation on select change

17 New Member
I am trying to get the financial calculation on this to trigger whenever there is a change to select1. Right now, the user has to click on select2 to trigger the changes.

Ideally, a change of select1

1. trigger the population of select2 (and set it initially to 0)
2. make the text fields disappear
3. trigger the financial calculation to reflect the select1 choice.

Any help would be greatly appeciated !

Greg





Expand|Select|Wrap|Line Numbers
  1.  
  2. <SCRIPT language="JavaScript"> 
  3.     var Opt2;
  4.      var Opt1;
  5.  
  6.     function addfields() {
  7.          var category = parseInt(document.getElementById("category").value);
  8.          var family = parseInt(document.getElementById("family").value);
  9.          document.getElementById("textfield").value=category+family;
  10.          document.getElementById("textfield2").value=category+family;
  11.  
  12.          var value = category + family; 
  13.          document.form1.textfield.value = isNaN(value) ? '' : value;
  14.          document.form1.textfield2.value = isNaN(value) ? '' : value;
  15.      }
  16.  
  17.  function PopulateSelect2(){
  18.      Opt1=document.form1.category;
  19.     Opt2=document.form1.family;
  20.     Opt2.options.length=0;
  21.     Opt2.options[Opt2.options.length]=new Option("0", 0);
  22.  
  23.     switch(Opt1.selectedIndex)
  24.     {
  25.         case 1:
  26.               Opt2.options[Opt2.options.length]=new Option("1", 40);
  27.             Opt2.options[Opt2.options.length]=new Option("2", 80);
  28.             Opt2.options[Opt2.options.length]=new Option("3", 120);
  29.             break;   
  30.         case 2:
  31.             Opt2.options[Opt2.options.length]=new Option("1", 40); break; 
  32.         case 3:
  33.             break;
  34.         case 4:
  35.             Opt2.options[Opt2.options.length]=new Option("1", 40);
  36.             Opt2.options[Opt2.options.length]=new Option("2", 80);
  37.             Opt2.options[Opt2.options.length]=new Option("3", 120);
  38.             break;
  39.         }
  40.     }
  41.  
  42.     function React2Select2()
  43.     {
  44.         var value;
  45.  
  46.         Opt2=document.form1.family;
  47.         document.getElementById('F1').style.display="none";
  48.         document.getElementById('F2').style.display="none";
  49.         document.getElementById('F3').style.display="none";
  50.         document.getElementById('Ft1').style.display="none";
  51.         document.getElementById('Ft2').style.display="none";
  52.         document.getElementById('Ft3').style.display="none";
  53.         switch(Opt2.selectedIndex)
  54.         {
  55.             case 1:
  56.                 document.getElementById('F1').style.display="block";
  57.                 document.getElementById('Ft1').style.display="block";
  58.                 break;   
  59.             case 2:
  60.                 document.getElementById('F1').style.display="block";
  61.                 document.getElementById('F2').style.display="block";
  62.                 document.getElementById('Ft1').style.display="block";
  63.                 document.getElementById('Ft2').style.display="block";
  64.                 break;
  65.             case 3:
  66.                 document.getElementById('F1').style.display="block";
  67.                 document.getElementById('F2').style.display="block";
  68.                 document.getElementById('F3').style.display="block";
  69.                 document.getElementById('Ft1').style.display="block";
  70.                 document.getElementById('Ft2').style.display="block";
  71.                 document.getElementById('Ft3').style.display="block";
  72.                 break;
  73.         }
  74.  
  75.         value=parseFloat(document.form1.family.value) + parseFloat(document.form1.category.value);
  76.         document.form1.textfield.value = isNaN(value) ? '' : value;
  77.          document.form1.textfield2.value = isNaN(value) ? '' : value;
  78.     }    
  79.  
  80. </SCRIPT> 
  81.  

Expand|Select|Wrap|Line Numbers
  1. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  2. <title>Untitled Document</title>
  3. <style type="text/css">
  4. <!--
  5. .style1 {color: #FF0000}
  6. .style3 {color: #FF0000; font-size: small; }
  7. .style4 {font-size: 12px}
  8. .style5 {font-size: 18px}
  9. -->
  10. </style>
  11. </head>
  12.  
  13. <body>
  14. <form id="form1" name="form1" method="post" action="">
  15.   <table width="700" border="1">
  16.     <tr>
  17.       <td><div align="right">Category</div></td>
  18.       <td><select name="category" id="category"  onchange="PopulateSelect2()" >
  19.         <option>Select a Category</option>
  20.         <option value="85">OMEA Member</option>
  21.         <option value="25">OCMEA Member</option>
  22.         <option value="45">Saturday Only</option>
  23.         <option value="200">Non Member</option>
  24.       </select></td>
  25.       <td>&nbsp;</td>
  26.     </tr>
  27.     <tr>
  28.       <td><div align="right">Family Attending</div></td>
  29.       <td>
  30.       <select name="family" id="family" onchange="React2Select2();" onclick="React2Select2();">
  31.     </select>
  32.       </td>
  33.       <td>&nbsp;</td>
  34.     </tr>
  35.     <tr>
  36.       <td><div align="right">Total Fees</div></td>
  37.       <td bgcolor="#FFFFFF"><span class="style3"> $</span>
  38.         <input name="textfield" type="text" disabled="disabled" class="style1" id="textfield" /></td>
  39.       <td>&nbsp;</td>
  40.     </tr>
  41.     <tr>
  42.       <td valign="top">
  43.           <div align="right" id="F1" style="display:none;" >Family Member1</span></div>
  44.  
  45.             <div align="right" id="F2" style="display:none;">Family Member2</span></div>
  46.  
  47.           <div align="right" id="F3" style="display:none;">Family Member3</span></div>
  48. &nbsp;     </td>
  49.       <td bgcolor="#FFFFFF">
  50.           <div id="Ft1" style="display:none;"><input name="Family1" type="text" id="Family1" /></div>
  51.  
  52.             <div id="Ft2" style="display:none;"><input name="Family2" type="text" id="Family2" /></div>
  53.  
  54.           <div id="Ft3" style="display:none;"><input name="Family3" type="text" id="Family3" /></div>
  55.           &nbsp;
  56.       </td>
  57.       <td>&nbsp;</td>
  58.     </tr>
  59.     <tr>
  60.       <td>&nbsp;</td>
  61.       <td bgcolor="#FFFFFF"><input type="text" name="textfield2" id="textfield2" DISABLED /></td>
  62.       <td>&nbsp;</td>
  63.     </tr>
  64.   </table>
  65.   <p>&nbsp;</p>
  66. </form>
  67. </body>
  68. </html>
  69.  
  70.  
Sep 8 '07 #1
4 2408
gregincolumbus
17 New Member
Anyone able to help me on this? Please?

Thanks

Greg
Sep 8 '07 #2
pbmods
5,821 Recognized Expert Expert
Heya, Greg.

First off:

[CODE=javascript]
JavaScript code goes here.
[/CODE]

and

[CODE=html]
HTML code goes here.
[/CODE]

and so on.

To answer your question, can you add the function call to the onchange attribute for your select element?
Sep 8 '07 #3
gregincolumbus
17 New Member
Hi

Thanks for the response..sorry about the code tags...thought I was doing it right....will do better next time :)

I am a newbie to javascript. The code I sent was written by somebody else who I paid a small deposit to write it but he never finished it completely. I was supposed to pay the balance when the work was completed.

I have tried contacting him but have gotten no response...so I am trying to get this thing finished and out the door..I am on a tight timeline for a project I volunteered to do.

How do I add the function call to the onchange attribute?

Sorry for all the newbie questions.

Thanks

Greg
Sep 8 '07 #4
pbmods
5,821 Recognized Expert Expert
Heya, Greg.

Oh goodie.

Alrightey. On this line here:
Expand|Select|Wrap|Line Numbers
  1. <td><select name="category" id="category"  onchange="PopulateSelect2()" >
  2.  
you're setting the onchange handler to 'PopulateSelect2()'. In other words, when the selected value changes, the browser will automatically call PopulateSelect2().

All you need to do from here is create the function that does all the stuff you need it to and add it to the event handler, e.g.:

Expand|Select|Wrap|Line Numbers
  1. <td><select name="category" id="category"  onchange="PopulateSelect2(); RunFinancialCalculations();" >
  2.  
That should get you started; we'll go from there :)
Sep 8 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
3432
by: Dave C. | last post by:
Hello, I have created the following trigger: CREATE TRIGGER tr_UDFTest ON UserDefinedFields FOR INSERT, UPDATE AS DECLARE @foobar varchar(100) SELECT @foobar= foobar FROM inserted IF (...
8
8583
by: Jason | last post by:
I have a table that matches up Securities and Exchanges. Individual securities can belong on multiple exchanges. One of the columns, named PrimaryExchangeFlag, indicates if a particular exchange is...
3
21457
by: Mike | last post by:
I have never written a trigger before, but I have a couple of uses for them now so I am trying. I have a view that I created and I want to have this trigger, run anytime the view is run. I don't...
6
8254
by: John Bentley | last post by:
John Bentley writes at this level: If we think about our savings accounts then division never comes in (as far as I can see). We deposit and withdraw exact amounts most of the time. Occasionaly...
1
15384
by: shottarum | last post by:
I currently have 2 tables as follows: CREATE TABLE . ( mhan8 int, mhac02 varchar(5), mhmot varchar(5), mhupmj int )
7
1755
by: rkrueger | last post by:
Given the following 3 Tables: CREATE TABLE ( NOT NULL , NOT NULL CONSTRAINT DEFAULT (getdate()), NULL , CONSTRAINT PRIMARY KEY CLUSTERED (
2
7366
by: IntraRELY | last post by:
I know this isnt really a VB question per say, but is what I am developing in VB.NET and Excel is the only place that has provided direction. I wanted to ask the public if perhaps you could lend me...
2
2375
by: dean.cochrane | last post by:
I have inherited a large application. I have a table which contains a hierarchy, like this CREATE TABLE sample_table( sample_id int NOT NULL parent_sample_id int NOT NULL ....lots of other...
1
7253
by: djdevx | last post by:
Dear all PostgreSQL xperts! Hi, I am newbie in PostgreSQL. I am currently developing an app that use PostgreSQL as a BackEnd Database. Now I am having problem with the function trigger since last...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5430
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4864
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.