Ich möchte einige Preise zusammenfassen und in Alle Preiseingabe setzen, aber die Funktion summiert die Zahlen nicht, es setzt die Zahlen nebeneinander. Gibt es einen Code, der die Zeichenfolge in die Nummer ändert?Alle Preise summieren sich nicht die Preise stattdessen setzt es die Preise nebeneinander
<html>
<label class="fa">ext modeling price</label>
<input type="number" class="form-control" onchange="allPrc();" id="model-
ext-price" placeholder= "0" ></input>
<br>
<label class="fa">int modeling price</label>
<input type="number" class="form-control" onchange="allPrc();" id="model-
int-price" placeholder= "0" ></input>
<hr class="hrline">
<label class="fa"> ext renderign price</label>
<input type="number" class="form-control" onchange="allPrc();" id="render-
ext-price" placeholder= "0" ></input>
<br>
<label class="fa">int rendering price </label>
<input type="number" class="form-control" onchange="allPrc();" id="render-
int-price" placeholder= "0" y></input>
<hr class="hrline">
<label class="fa">pproduction price </label>
<input type="number" class="form-control" onchange="allPrc();"
id="pproduction-price" placeholder= "0" y></input>
<hr class="hrline">
<label class="fa"> All price </label>
<input type="number" class="form-control" id="All-price" placeholder= "0"
readonly></input>
</html>
<script>
document.getElementById ('model-ext-price').onchange = function() {allPrc();};
document.getElementById ('model-int-price').onchange = function() {allPrc();};
document.getElementById ('render-ext-price').onchange = function() {allPrc();};
document.getElementById ('render-int-price').onchange = function() {allPrc();};
document.getElementById ('pproduction-price').onchange = function() {allPrc();};
var allPrc = function() {
var Totalextmdl = document.getElementById ('model-ext-price').value,
Totalintmdl = document.getElementById ('model-int-price').value,
Totalextrndr = document.getElementById ('render-ext-price').value,
Totalintrndr = document.getElementById ('render-int-price').value,
Totalpp = document.getElementById ('pproduction-price').value,
TotalPrc = 0;
document.getElementById('All-price').value = TotalPrc;
var TotalPrc = Totalextmdl + Totalintmdl + Totalextrndr + Totalintrndr +
Totalpp;
document.getElementById('All-price').value = (TotalPrc>0 &&
TotalPrc!=='NaN')?TotalPrc:0;
};
</script>
Es weil JS glauben, dass dies eine Zeichenkette, also das Plus-Zeichen nur im Grunde Concat-Zeichenketten. Sie müssen Ihre Zahlen in floats zerlegen: '' 'parseFloat (Totalextmdl = document.getElementById ('model-ext-price'). Value)' '' – Treast