Hilfe bei Script benötigt!
Ulrich
- javascript
Hallo,
benötige Hilfe bei einem Berechnungsscript, im HTML-Code findet ihr ein Selectbox- Feld bei "ein3", allerdings aktualisiert das Summenfeld nicht wenn ich die Option wähle.
Dann hab ich noch das Problem, dass ich nur bis ein9 bzw. preis9 komme, ab 10 macht er mir probleme und verwechselt die Angabe mit ein1 bzw. preis1.
Kann jemand dabei helfen bzw. das Problem lösen?
Thx! Ulrich
<html>
<head><script language="JavaScript"> <!-- function init() { preis1=document.form1.ein1.value; preis2=document.form1.ein2.value; preis3=document.form1.ein3.value; preis4=document.form1.ein4.value; preis5=document.form1.ein5.value; preis6=document.form1.ein6.value; preis7=document.form1.ein7.value; preis8=document.form1.ein8.value; preis9=document.form1.ein9.value; }
function changed(obj) { var anz; var soll; var diff; var typ=obj.name.substring(0,3); var num=obj.name.charAt(3);
if(typ == "anz") { var anz=parseInt(obj.value); if(!(anz > 0)) { anz=0; obj.value="0"; } document.form1["ges"+num].value=parseFloat(document.form1["ein"+num].value)*anz;
} else if(typ == "ges") { anz=parseInt(document.form1["anz"+num].value); soll=parseFloat(document.form1["ein"+num].value)*anz; diff=parseFloat(document.form1["ges"+num].value) - soll; if(diff > 0.005) { alert("Danke !"); } else if(diff < -0.005) { alert("Nicht mit mir !"); document.form1["ges"+num].value=soll; } }
var total=0; for (num=1; num<=9; num++) { total+=parseFloat(document.form1["ges"+num].value); } document.form1.total.value=total;
var total2=0; for (num=2; num<=2; num++) { total2+=parseFloat(document.form1["ges"+num].value); } document.form1.total2.value=total2; }
function check() { var status=true; var email=document.form1.mailto.value; if(email == "") { alert("Bitte geben Sie Ihre email-Adresse ein !"); status=false; } else { kk=email.indexOf("@"); if(kk <= 0 || email.indexOf(".", kk) < 0) { alert("email-Adresse ist nicht korrekt !"); status=false; } } var anz=0; for (num=1; num<=9; num++) { anz+=parseFloat(document.form1["anz"+num].value); } if(anz < 1) { alert("es wurde nichts bestellt !"); status=false; } if(status)status=confirm("Sie haben "+anz+" Leistungen ausgewählt."); return status; } //--> </script>
<title>xxxxxx</title> </head>
<body onLoad="init();" bgcolor="#FFFFFF" topmargin="5" leftmargin="5">
<p align="center"><font face="Times New Roman" color="#000080"><big><big><strong><u>xxxxxx</u></strong></big></big></font></p>
<form name="form1" method="post" action="/cgi-bin/ub/cgi-mail" onSubmit="return check();" onReset="return confirm('wirklich rücksetzen ?');"> <input type="hidden" name="subject" value="Tarifauswahl"><h3><u><em><font face="Times New Roman">Auswahl</font></em></u></h3> <p><font face="Times New Roman">Ihre Emailadresse:<br> <input type="text" name="mailto" size="32"> </font></p> <table border="1" width="626" height="166"> <tr> <th width="57" height="19"><font face="Times New Roman">Anzahl</font></th> <th width="363" height="19"><font face="Times New Roman">Bezeichnung</font></th> <th width="91" height="19"><font face="Times New Roman">Einzelpreis</font></th> <th width="87" height="19"><font face="Times New Roman">Gesamtpreis </font></th> </tr> <tr> <td width="57" height="23"><font face="Times New Roman"><input type="text" name="anz1" size="3" value="1" onChange="changed(this);" readonly> </font></td> <td width="363" height="23"><font face="Times New Roman">Preis 1</font></td> <td width="91" height="23"><font face="Times New Roman"><input type="text" name="ein1" size="7" value="7.90" onChange="changed(this);" readonly>EUR </font></td> <td width="87" height="23"><font face="Times New Roman"><input type="text" name="ges1" size="4" value="7.90" onChange="changed(this);" readonly>EUR </font></td> </tr> <tr> <td width="57" height="23"><select size="1" name="anz2" onChange="changed(this);"> <option selected value="0">0</option> <option value="120">1</option> <option value="250">2</option> <option value="500">5</option> </select></td> <td width="363" height="23"><font face="Times New Roman">Preis 2</font></td> <td width="91" height="23"><font face="Times New Roman"><input type="text" name="ein2" size="7" value="1.50" onChange="changed(this);">EUR </font></td> <td width="87" height="23"><font face="Times New Roman"><input type="text" name="ges2" size="4" value="0" onChange="changed(this);" readonly>EUR </font></td> </tr> <tr> <td width="57" height="23"><font face="Times New Roman"><input type="text" name="anz3" size="3" value="1" onChange="changed(this);" readonly> </font></td> <td width="363" height="23"><select size="1" name="ein3" onChange="changed(this);"> <option value="0.00">inkl. (0,00 EUR)</option> <option value="2.00">inkl. (zzgl. 2,00 EUR)</option> </select></td> <td width="91" height="23"></td> <td width="87" height="23"><font face="Times New Roman"><input type="text" name="ges3" size="4" value="0" onChange="changed(this);" readonly>EUR </font></td> </tr> <tr> <td width="57" height="23"><font face="Times New Roman"><input type="text" name="anz4" size="3" value="0" onChange="changed(this);"> </font></td> <td width="363" height="23"><font face="Times New Roman">Preis 4</font></td> <td width="91" height="23"><font face="Times New Roman"><input type="text" name="ein4" size="7" value="6.90" onChange="changed(this);">EUR </font></td> <td width="87" height="23"><font face="Times New Roman"><input type="text" name="ges4" size="4" value="0" onChange="changed(this);" readonly>EUR </font></td> </tr> <tr> <td width="57" height="23"><font face="Times New Roman"><input type="text" name="anz5" size="3" value="0" onChange="changed(this);"> </font></td> <td width="363" height="23"><font face="Times New Roman" size="3">Preis 5</font></td> <td width="91" height="23"><font face="Times New Roman"><input type="text" name="ein5" size="7" value="6.90" onChange="changed(this);">EUR </font></td> <td width="87" height="23"><font face="Times New Roman"><input type="text" name="ges5" size="4" value="0" onChange="changed(this);" readonly>EUR </font></td> </tr> <tr> <td width="57" height="23"><font face="Times New Roman"><input type="text" name="anz6" size="3" value="0" onChange="changed(this);"> </font></td> <td width="363" height="23"><font face="Times New Roman">Preis 6</font></td> <td width="91" height="23"><font face="Times New Roman"><input type="text" name="ein6" size="7" value="6.80" onChange="changed(this);">EUR </font></td> <td width="87" height="23"><font face="Times New Roman"><input type="text" name="ges6" size="4" value="0" onChange="changed(this);" readonly>EUR </font></td> </tr> <tr> <td width="57" height="23"><font face="Times New Roman"><input type="text" name="anz7" size="3" value="0" onChange="changed(this);"> </font></td> <td width="363" height="23"><font face="Times New Roman">text</font></td> <td width="91" height="23"><font face="Times New Roman"><input type="text" name="ein7" size="7" value="0.00" onChange="changed(this);">EUR </font></td> <td width="87" height="23"><font face="Times New Roman"><input type="text" name="ges7" size="4" value="0" onChange="changed(this);" readonly>EUR </font></td> </tr> <tr> <td width="57" height="23"><font face="Times New Roman"><input type="text" name="anz8" size="3" value="0" onChange="changed(this);"> </font></td> <td width="363" height="23"><font face="Times New Roman">text</font></td> <td width="91" height="23"><font face="Times New Roman"><input type="text" name="ein8" size="7" value="0.00" onChange="changed(this);">EUR </font></td> <td width="87" height="23"><font face="Times New Roman"><input type="text" name="ges8" size="4" value="0" onChange="changed(this);" readonly>EUR </font></td> </tr> <tr> <td width="57" height="23"><font face="Times New Roman"><input type="text" name="anz9" size="3" value="0" onChange="changed(this);"> </font></td> <td width="363" height="23"><font face="Times New Roman">text</font></td> <td width="91" height="23"><font face="Times New Roman"><input type="text" name="ein9" size="7" value="0.00" onChange="changed(this);">EUR </font></td> <td width="87" height="23"><font face="Times New Roman"><input type="text" name="ges9" size="4" value="0" onChange="changed(this);" readonly>EUR </font></td> </tr> <tr> <td width="57" height="23"><font face="Times New Roman"> </font></td> <th width="363" height="23"><font face="Times New Roman">Summe 1</font></th> <td width="91" height="23"><font face="Times New Roman"> </font></td> <td width="87" height="23"><font face="Times New Roman"><input type="text" name="total" size="5" onChange="changed(this);" readonly>EUR </font></td> </tr> <tr> <td width="57" height="23"><font face="Times New Roman"> </font></td> <th width="363" height="23"><font face="Times New Roman"> Summe 2 von ein2</font></th> <td width="91" height="23"><font face="Times New Roman"> </font></td> <td width="87" height="23"><font face="Times New Roman"><input type="text" name="total2" size="5" onChange="changed(this);" readonly>EUR </font></td> </tr> </table> <p><font face="Times New Roman"><input type="submit" value="Bestellen"> <input type="reset" value="Rücksetzen"> </font></p> </form> </body> </html>
Thx. Ulrich
Noch ein Hinweis zum Script:
bei anz2 ist kein Fehler, da habe ich nur vergessen die Werte auf 1, ... zu ändern, sind momentan noch auf 120, 250, ...
Hallo,
benötige Hilfe bei einem Berechnungsscript, im HTML-Code findet ihr ein Selectbox- Feld bei "ein3", allerdings aktualisiert das Summenfeld nicht wenn ich die Option wähle.
Dann hab ich noch das Problem, dass ich nur bis ein9 bzw. preis9 komme, ab 10 macht er mir probleme und verwechselt die Angabe mit ein1 bzw. preis1.
Kann jemand dabei helfen bzw. das Problem lösen?
Du programmierst normalerweise VB oder?
Der Javascript code ist typisch VB Programmierer - keine Arrays wo welche hingehören wurden.
aber der HTML Code ist noch schlimmer. Bei mir ist erstmal ein halbe Seite weiss und dan hab ich ein Formular in dem ich nichts eingeben kann und keine selectbox nirgendwo. Vielleicht wäre mal eine Funktionsbeschriebung und oder ein auf das notwendigste gekürzter Code nicht schlecht.
Struppi.