473,320 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

change value for calculation - help

cassbiz
202 100+
I may be in the wrong forum so Ronald don't shoot :)

In my code I have an option box to choose a number - works fine. I want to carry over the new value to another field to do a recalculation.

Primarily the field "$preis1" to change with the javascript.

Here is the code.

Expand|Select|Wrap|Line Numbers
  1.         <script type="text/javascript">
  2.                 <!--
  3.                 function perscount()
  4.                 {
  5.                 if (document.daten.pers.value==1){
  6.                 document.daten.preis.value = document.daten.preis1.value;}
  7.                 if (document.daten.pers.value==2){
  8.                 document.daten.preis.value = document.daten.preis2.value;}
  9.                 if (document.daten.pers.value==3){
  10.                 document.daten.preis.value = document.daten.preis3.value;}
  11.                 if (document.daten.pers.value==4){
  12.                 document.daten.preis.value = "";}
  13.                 }
  14.                         //-->
  15.         </script>
  16. <?
  17. $zdaten = getzimmer();
  18. $i=0;
  19. while  (count ($zdaten) >= $i)
  20. {
  21.         $i++;
  22.         if ($zdaten[$i][1]==$zimmer)
  23.         {
  24.                 $preis1=$zdaten[$i][2];
  25.                 $preis2=$zdaten[$i][3];
  26.                 $preis3=$zdaten[$i][4];
  27.                 $preis4=$zdaten[$i][5];
  28.                 $preis5=$zdaten[$i][6];
  29.         }
  30. }
  31. ?>
  32. <input type="hidden" name="preis1" value=<? echo "'$preis1'"?>>
  33. <input type="Hidden" name="preis2" value=<? echo "'$preis2'"?>>
  34. <input type="Hidden" name="preis3" value=<? echo "'$preis3'"?>>
  35. <input type="Hidden" name="preis4" value=<? echo "'$preis4'"?>>
  36. <input type="Hidden" name="preis5" value=<? echo "'$preis5'"?>>
  37.  
  38.  <!--took out the blah blah -->
  39.  
  40.  
  41.         <tr id="tr2">
  42.                 <td align = "center" class="t1">
  43.                         <? echo $t_forms['pers'] ?> <br>
  44.                         <select name="pers" size="1" onChange="perscount()">
  45.                         <option <? if ($pers==1) echo 'selected'; ?>>1</option>
  46.                         <option <? if ($pers==2) echo 'selected'; ?>>2</option>
  47.                         <option <? if ($pers==3) echo 'selected'; ?>>3</option>
  48.                         <option <? if ($pers==4) echo 'selected'; ?>>4</option>
  49.                 </td>
  50.         </tr>
  51.         <tr id="tr2">
  52.                 <td class="t1">
  53. <? echo $t_forms['price_day'] ?> <input name="preis" size="20" class="t1" maxlength="20" value=<?echo "'$preis1'" ?> >
  54. <?
  55.         $nächte1 = ($abdatum-$andatum)/86400;
  56.         $nächte2 = $nächte1 + 0.5;
  57.         $nächte = round($nächte2);
  58.  
  59. <!-- I would like to change the value of $pries1 to the new value given by the javascript to do the calculation. -->
  60.  
  61.         $sum1 = $nächte * $preis1;
  62.         $sum = number_format($sum1, 2);
  63.         $tax1 = $t_global['tax'];
  64.         $tax2 = $sum1 * ($tax1 * .01);
  65.         $tax = number_format($tax2, 2);
  66.         $tot1 = $sum + $tax;
  67.         $tot2 = $sum1 + $tax2;
  68.         $tot = number_format($tot2, 2);
  69. ?>
  70.                 </td>
  71.         <tr id="tr2">
  72.                 <td class="t1" colspan="2">
  73.                         <? echo "{$t_forms['count']} : $nächte"; ?>
  74.                 </td>
  75.         <tr id="tr2">
  76.                 <td class="t1" colspan="2">
  77.                         <? echo "{$t_forms['sum']} = {$t_global['currency']} $sum"; ?>
  78.                 </td>
  79.         <tr id="tr2">
  80.                 <td class="t1" colspan="2">
  81.                         <? echo "{$t_forms['tax']} {$t_global['tax']}% = {$t_global['currency']} $tax"; ?>
  82.                 </td>
  83.         <tr id="tr2">
  84.                 <td class="t1" colspan="2">
  85.                         <? echo "{$t_forms['total']} {$t_global['currency']} $tot"; ?>
  86.                 </td>
  87.         </tr>
  88.  
Is there a real easy way to put that calculation into JavaScript so that it will change per the 'OnChange'? If so, I don't know very much about javascript.

Thanks in Advance
Dec 26 '06 #1
2 2154
ronverdonk
4,258 Expert 4TB
No, there is no easy way. JavaScript runs client-side and PHP at the server. (the code being in one script does not mean that they run on the same machine!). So you'll have to set up a communication between client and server. There are ways to do that, but you'll have to redesign your script for that.

You could start at the JS side and then put a httpRequest call to the backend PHP with the price passed. Only then could the php script execute.

I wonder if that is what you meant by an easy way? If so, you can pursue this using httpRequest (or Ajax). Good luck!

Ronald :cool:
Dec 26 '06 #2
cassbiz
202 100+
Do you know of a tutorial or possibly helping me out in changing the calculation over to js.

The value is not stored in a db it is only a visual on the screen and for print.
Dec 26 '06 #3

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

Similar topics

1
by: sentinel | last post by:
Hi, I'm currently writing a mulit-page form app that uses a session to retain data from each form element in order for the user to jump between pages, then the final data is passed to a calculation...
2
by: cs168 | last post by:
Hi I am new in ASP programming so I do use the very basic and simple way to do all my stuff. Now I do really got stuck at how can I loop thru the calculation for all my selection.. My full code is as...
4
by: Michiel Alsters | last post by:
Hello everybody, I hope anybody can help me. I'll try to give a brief overview of my problem. I have running a program that performs a heavy calculation. To give the user feedback what the...
9
by: Coleen | last post by:
Hi All :-) I found the way to get my column sum (Thanks Cor I did it a little different, but the result is what I wanted) I used: dt_stat_report_3b.Columns.Add(New DataColumn("Sum",...
4
by: gregincolumbus | last post by:
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...
8
by: mlwerth | last post by:
Dear Access Group: This is the most basic and most embarrassing of questions, but I cannot find where to change the data type of a text field that I have in Access 2003 to a number field. I've...
4
by: Lara1 | last post by:
I'm trying to write a procedure that will enable button on a sheet (and colour it red), but ONLY when changes are made to cells in column E of that sheet (from row 10 to the bottom of the...
1
by: zoeb | last post by:
Currently I have a table, and would like the calculate a field in the table by referencing values from another 3 tables. i.e. tblData Index1, Index2, Index3, Value 1 2 3 2...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.