0
I need some help that I’m stuck in here, and I don’t understand AJAX. I have these fields, select(tour), QTE(Adults) QTE(Child) TOTAL ( where performs the calculation). I need that when calculating, when clicking on the icon, also pass to another form, the values: TOUR and the calculated TOTAL, have to do this, do not want to send to another page.
<td>
<div>
<select class="form-control" name="tour" id="tour">
<option>Choose a tour</option>
<option value="98">Douro Valley Tour</option>
<option value="118">Bairrada Wine Tour</option>
</select>
</div>
</td>
<td>
<div class="numbers-row">
<input type="text" value="1" id="adults" class="qty2 form-control" name="adults">
</div>
</td>
<td>
<div class="numbers-row">
<input type="text" value="0" id="child" class="qty2 form-control" name="child">
</div>
</td>
<td>
<span id="soma"></span>
</td>
<td class="options">
<a href='javascript:calcular();'><i class="icon-ccw-2"></i></a>
</td>
</tr>
</tbody>
</table>
<script>
function calcular() {
var unit = "45";
var tour = Number(document.getElementById("tour").value);
var adults = Number(document.getElementById("adults").value);
var child = Number(document.getElementById("child").value);
var elemResult = document.getElementById("soma");
if (elemResult.textContent === undefined) {
elemResult.textContent = String(tour * adults + unit * child)+ ".00€";
}
else { // IE
elemResult.innerText = String(tour * adults + unit * child) + ".00€";
}
}
</script>
<input type="hidden" name="item_name" value="SELECT">
<input type="hidden" name="amount" value="TOTAL">
Explain better what you mean by "pass to another form".
– bfavaretto
I just want to pass the value of select and the ID field where it shows Total, to the fields below....
– J. Campos
Start by placing an id in these fields. Then you can assign value with
document.getElementById('id-do-input').value = 'valor desejado';.– bfavaretto
My JS is very bad: the 'desired value' to pass the value of select which would be?
– J. Campos
You tell me. Wouldn’t be the values you already have in the variable
tour, in one of the inputs, and the result of your account in the other?– bfavaretto
yes, but then I only pass like . value='tour' --- tour
– J. Campos
Solved...thank you friend
– J. Campos