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
- <script type="text/javascript">
- <!--
- function perscount()
- {
- if (document.daten.pers.value==1){
- document.daten.preis.value = document.daten.preis1.value;}
- if (document.daten.pers.value==2){
- document.daten.preis.value = document.daten.preis2.value;}
- if (document.daten.pers.value==3){
- document.daten.preis.value = document.daten.preis3.value;}
- if (document.daten.pers.value==4){
- document.daten.preis.value = "";}
- }
- //-->
- </script>
- <?
- $zdaten = getzimmer();
- $i=0;
- while (count ($zdaten) >= $i)
- {
- $i++;
- if ($zdaten[$i][1]==$zimmer)
- {
- $preis1=$zdaten[$i][2];
- $preis2=$zdaten[$i][3];
- $preis3=$zdaten[$i][4];
- $preis4=$zdaten[$i][5];
- $preis5=$zdaten[$i][6];
- }
- }
- ?>
- <input type="hidden" name="preis1" value=<? echo "'$preis1'"?>>
- <input type="Hidden" name="preis2" value=<? echo "'$preis2'"?>>
- <input type="Hidden" name="preis3" value=<? echo "'$preis3'"?>>
- <input type="Hidden" name="preis4" value=<? echo "'$preis4'"?>>
- <input type="Hidden" name="preis5" value=<? echo "'$preis5'"?>>
- <!--took out the blah blah -->
- <tr id="tr2">
- <td align = "center" class="t1">
- <? echo $t_forms['pers'] ?> <br>
- <select name="pers" size="1" onChange="perscount()">
- <option <? if ($pers==1) echo 'selected'; ?>>1</option>
- <option <? if ($pers==2) echo 'selected'; ?>>2</option>
- <option <? if ($pers==3) echo 'selected'; ?>>3</option>
- <option <? if ($pers==4) echo 'selected'; ?>>4</option>
- </td>
- </tr>
- <tr id="tr2">
- <td class="t1">
- <? echo $t_forms['price_day'] ?> <input name="preis" size="20" class="t1" maxlength="20" value=<?echo "'$preis1'" ?> >
- <?
- $nächte1 = ($abdatum-$andatum)/86400;
- $nächte2 = $nächte1 + 0.5;
- $nächte = round($nächte2);
- <!-- I would like to change the value of $pries1 to the new value given by the javascript to do the calculation. -->
- $sum1 = $nächte * $preis1;
- $sum = number_format($sum1, 2);
- $tax1 = $t_global['tax'];
- $tax2 = $sum1 * ($tax1 * .01);
- $tax = number_format($tax2, 2);
- $tot1 = $sum + $tax;
- $tot2 = $sum1 + $tax2;
- $tot = number_format($tot2, 2);
- ?>
- </td>
- <tr id="tr2">
- <td class="t1" colspan="2">
- <? echo "{$t_forms['count']} : $nächte"; ?>
- </td>
- <tr id="tr2">
- <td class="t1" colspan="2">
- <? echo "{$t_forms['sum']} = {$t_global['currency']} $sum"; ?>
- </td>
- <tr id="tr2">
- <td class="t1" colspan="2">
- <? echo "{$t_forms['tax']} {$t_global['tax']}% = {$t_global['currency']} $tax"; ?>
- </td>
- <tr id="tr2">
- <td class="t1" colspan="2">
- <? echo "{$t_forms['total']} {$t_global['currency']} $tot"; ?>
- </td>
- </tr>
Thanks in Advance