I’m making an online hotel booking form and ran into a problem: I’ve added a function to automatically calculate the cost depending on the client’s choice, it’s all displayed in the span tag, I’m not able to pull the final amount into the handler.

Counting Script:

<script type="text/javascript"> function calc() { var bookingInputRoom1 = document.getElementById("bookingInputRoom1"); var bookingInputRoom2 = document.getElementById("bookingInputRoom2"); var col1 = document.getElementById("col1"); var col2 = document.getElementById("col2"); var result = document.getElementById("result"); var price = 0; price += (col1.checked == true) ? parseInt(bookingInputRoom1) : 0; price += (col2.checked == true) ? parseInt(bookingInputRoom2) : 0; result.innerHTML = price; } </script> 

So I deduce the cost:

 Стоимость бронирования: <span id="result" value="0" name="summa">0</span> руб 

How to display the amount correctly so that you can later send it to the handler? Thank you in advance!

  • First of all, what is the result? It is not announced anywhere, does not refer to anything. - Artem Nikolaev
  • And most likely they forgot to extract the data from the document.getElementById ("bookingInputRoom2") input. Value - Artem Nikolaev
  • Edited, just forgot to declare result here, in the full version all the rules. The fact is that the price I have displayed is excellent, I can not send it to the handler - Derp
  • one
    Rule number 1: "Never trust the client." This means that the amount received should not be sent to the server. The server based on some data should count it. Even if the logic is duplicated at the client. - ArchDemon
  • one
    simpler but not safer. transfer any identifiers of the selected fields to the server, and read there. - ya.ymer

0