2016-04-11 7 views
-1

yeah im einige Probleme mit diesem haben, berechnen es wird nicht die Preise, und ich hatte gehofft, würde jemand mirJavascript Gesamtpreis Calculator?

function calculatePrice(myForm){ 
 

 
    //Get selected data 
 
    var elt = document.getElementById("tickets1"); 
 
    var tickets1 = elt.options[elt.selectedIndex].value; 
 
    
 
    var elt = document.getElementById("tickets2"); 
 
    var tickets2 = elt.options[elt.selectedIndex].value; 
 
    
 
    //convert data to integers 
 
    tickets1 = parseInt(tickets1); 
 
    tickets2 = parseInt(tickets2); 
 
    
 
    //calculate total value 
 
    var total = tickets1 + tickets2; 
 
    
 
    //print value to PicExtPrice 
 
    document.getElementById("PicExtPrice").value=total; 
 
}
<!DOCTYPE html> 
 
<html> 
 
\t <head> 
 
\t <link rel="stylesheet" type="text/css" href="../CSS/stylepage.css"> 
 
\t <script type="text/javascript" src="../JS/prcecal.js"> 
 
\t </script> 
 
\t </head> 
 
\t <center> 
 
\t \t <body> 
 
\t \t \t <fieldset> 
 
\t \t \t <div id="box_1"> 
 
\t \t \t <center><h2>Order</h2></center> 
 
\t \t \t \t <form name="myForm"> 
 
\t \t \t \t \t Email: 
 
\t \t \t \t \t <br> 
 
\t \t \t \t \t <input type="email" name="email" id="email" required /> 
 
\t \t \t \t \t <br> 
 
\t \t \t \t \t <br> 
 
\t \t \t \t \t Date: 
 
\t \t \t \t \t <br> 
 
\t \t \t \t \t <input type="date" name="date" id="date" min="today" required /> 
 
\t \t \t \t \t <br> 
 
\t \t \t \t \t <br> 
 
\t \t \t \t \t <div id="dropdowns"> 
 
\t \t \t \t \t <SELECT NAME="Ticketsadults" onChange="calculatePrice()" id="tickets1"> 
 
\t \t \t \t \t <OPTION value="0">0</OPTION> 
 
\t \t \t \t \t <OPTION value="20">1</OPTION> 
 
\t \t \t \t \t <OPTION value="40">2</OPTION> 
 
\t \t \t \t \t <OPTION value="60">3</OPTION> 
 
\t \t \t \t \t <OPTION value="80">4</OPTION> 
 
\t \t \t \t \t </SELECT> 
 
\t \t \t \t \t <br> 
 
\t \t \t \t \t <SELECT NAME="Ticketskids" onChange="calculatePrice()" id="tickets2" > 
 
\t \t \t \t \t <OPTION value="0">0</OPTION> 
 
\t \t \t \t \t <OPTION value="20">1</OPTION> 
 
\t \t \t \t \t <OPTION value="40">2</OPTION> 
 
\t \t \t \t \t <OPTION value="60">3</OPTION> 
 
\t \t \t \t \t <OPTION value="80">4</OPTION> 
 
\t \t \t \t \t </SELECT> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t \t <br> 
 
\t \t \t \t \t <br> 
 
\t \t \t \t \t <br> 
 
\t \t \t \t \t <button type="button" onclick="calculatePrice()">Calculate</button> 
 
\t \t \t \t \t <INPUT type="text" id="PicExtPrice" Size=8> 
 
\t \t \t \t \t </form> 
 
\t \t \t </center> 
 
\t \t </div> 
 
\t </fieldset> 
 
\t </body> 
 
</html> 
 
\t

Ive versuchte es um und Sachen ändern, aber es wird nicht bitte noch helfen könnte calcualte das beide Auswahl Dropdown-Menü

+1

Die Browser-Konsole sagt Ihnen buchstäblich den genauen Fehler. Sie haben die Variablen 'tick1' oder' tick2' nie definiert. – David

+0

Öffnen Sie das Browser-Debug-Fenster (F12). –

+0

Suman Lama, du bist keine Hilfe – Simbeazy

Antwort

0

Sie setzen parseInt(tick1) und parseInt(tick2) statt parseInt(tickets1) und parseInt(tickets2).

Sie setzen auch tick1 + tick2 statt tickets1 + tickets2.

+2

Was ist dann mit dem 'parseInt' Teil? –

+0

@RajaprabhuAravindasamy Danke, es ist jetzt behoben. – 4castle

+0

ja, das funktioniert immer noch nicht – Simbeazy

Verwandte Themen