Richie: Formular auslesen mit Javascript

Beitrag lesen

<body>

<form name="MIPFormular" action="mailto:email@somewhere.com" method="post" language="javascript" id="MIPFormular"

onsubmit="return sendFormular(this,'email@somewhere.com',700,300);">

<input type="hidden" name="FormName" value="MIP-Formular" />   <table border="0" cellpadding="5" cellspacing="0">     <tr>       <td align="left" width="300">Name:</td>       <td>       <input name="Name" type="text" size="40" maxlength="75" /></td>     </tr>     <tr>       <td align="left" width="300">E-mail:</td>       <td>       <input type="text" size="40" name="Mail"></td>     </tr>     <tr>       <td align="left" width="300">Telefon:</td>       <td>       <input type="text" size="40" name="Phone"></td>     </tr>     <tr>       <td align="left" width="300">Das Produkt stammt aus folgendem Bereich:</td>       <td><select name="Produktbereich" size="1" onchange="swap();">         <option value="Entertainment Devices">Entertainment Devices</option>         <option value="Handhelds">Handhelds</option>         <option value="Tablet PCs">Tablet PCs</option>         <option value="Notebooks">Notebooks</option>         <option value="Thin Clients">Thin Clients</option>         <option value="Personal Computers">Personal Computers</option>         <option value="Workstations">Workstations</option>         <option value="Broadband Solutions">Broadband Solutions</option>         <option value="Servers">Servers</option>         <option value="Storage">Storage</option>         <option value="Software">Software</option>         <option value="Displays/Accesories">Displays/Accesories</option>       </select></td>     </tr>     <tr>       <td>

</td>     </tr>     <tr>       <td align="left" width="300">Das Produkt lässt sich in folgende Unterkategorie einordnen:</td>       <td><select name="Unterkategorie" size="1">         <option value id="u0">Unterkategorie</option>         <option value id="u1">.</option>         <option value id="u2">.</option>         <option value id="u3">.</option>         <option value id="u4">.</option>         <option value id="u5">.</option>         <option value id="u6">.</option>         <option value id="u7">.</option>       </select></td>     </tr>   </table>

<table border="0" cellpadding="5" cellspacing="0">     <tr>       <td align="left" width="300">Folgende Features gehören dazu:</td>       <td width="120">       <input type="checkbox" name="Feature" checked="checked" value="0" />USB<br>       <input type="checkbox" name="Feature" checked="checked" value="1" />Firewire<br>       <input type="checkbox" name="Feature" checked="checked" value="2" />Grafikkarte<br>       <input type="checkbox" name="Feature" checked="checked" value="3" />usw1<br>       <input type="checkbox" name="Feature" checked="checked" value="4" />usw2<br>       </td>       <td width="120">       <input type="checkbox" name="Feature" checked="checked" value="5" />usw3<br>       <input type="checkbox" name="Feature" checked="checked" value="6" />usw4<br>       <input type="checkbox" name="Feature" checked="checked" value="7" />usw5<br>       <input type="checkbox" name="Feature" checked="checked" value="8" />usw6<br>       <input type="checkbox" name="Feature" checked="checked" value="9" />usw7<br>       </td>       <td width="120">       <input type="checkbox" name="Feature" checked="checked" value="10" />usw8<br>       <input type="checkbox" name="Feature" checked="checked" value="11" />usw9<br>       <input type="checkbox" name="Feature" checked="checked" value="12" />usw10<br>       <input type="checkbox" name="Feature" checked="checked" value="13" />usw11<br>       <input type="checkbox" name="Feature" checked="checked" value="14" />usw12<br>       </td>     </tr>   </table>

<table border="0" cellpadding="5" cellspacing="0">     <tr>       <td align="left" width="300">Frage 1?</td>       <td><textarea name="frage1" rows="5" cols="40"></textarea></td>     </tr>     <tr>       <td align="left" width="300">Frage 2?</td>       <td><textarea name="frage2" rows="5" cols="40"></textarea></td>     </tr>  <tr>       <td align="left" width="300">Frage 3?</td>       <td><textarea name="frage3" rows="5" cols="40"></textarea></td>     </tr>     <tr>       <td align="left" width="300">Frage 4?</td>       <td><textarea name="frage4" rows="5" cols="40"></textarea></td>     </tr>     <tr>       <td align="left">     <tr>       <td align="left" width="300">Bemerkungen:</td>       <td><textarea name="Meinung" rows="15" cols="40"></textarea></td>     </tr>     <tr>       <td height="10"></td>     </tr>     <tr>       <td colspan="2" align="center">       <input type="submit" value="Submit">       <input type="reset" value="Reset"></td>     </tr>   </table>

</form>

<script type="text/javascript"> <!-- function sendFormular(docForm,email,weite,hoehe) {   if (docForm.Name.value.length == 0){     alert ("Sie haben Ihren Namen nicht angegeben!");     docForm.Name.focus();     return false;   }   if (docForm.Phone.value.length == 0){     alert ("Sie haben keine Telefonnummer eingegeben!");     docForm.Phone.focus();     return false;   }

// if (navigator.appName != "Microsoft Internet Explorer") return true;

var wert = new Array();   wert[0] = docForm.Name.value;   wert[1] = docForm.Mail.value;   wert[2] = docForm.Phone.value;   wert[3] = docForm.Produktbereich.options[docForm.Produktbereich.selectedIndex].value;   wert[4] = docForm.Unterkategorie.options[docForm.Unterkategorie.selectedIndex].value;   wert[5] = ""; //leer, Zuweisung später in der for-Schleife   wert[6] = docForm.Meinung.value;

//Ein Array für die Auswertung des Formulars wird erstellt.   var t = new Array();

t[0] = "Name: " + docForm.Name.value;   t[1] = "E-mail: " + docForm.Mail.value;   t[2] = "Telefon: " + docForm.Phone.value;   t[3] = "Produktbereich: " + docForm.Produktbereich.options[docForm.Produktbereich.selectedIndex].value;   t[4] = "Unterkategorie: " + docForm.Unterkategorie.options[docForm.Unterkategorie.selectedIndex].value;

//Hier werden die Checkboxes für die Features ausgelesen und in den Array geschrieben.   for(var i=0; i<(docForm.Feature.length); i++){     if ((docForm.Feature[i].checked == true)&&(i<(docForm.Feature.length))){      wert[5] = wert[5] + docForm.Feature[i].value + ", ";     }   }   t[5] = "Features: " + wert[5];

t[6] = "Bemerkungen: " + docForm.Meinung.value;

var x = (screen.width - weite - 10) / 2;   var y = (screen.height - hoehe - 32) / 2;   var fenster = "width=" + weite + ",height=" + hoehe               + ",left=" + x + ",top=" + y + ",scrollbars=yes";   var Formular = window.open("","PopUp",fenster); Formular.focus();   Formular.document.open();   Formular.document.write("<html><head><title>Formular</title></head>");   Formular.document.write("<body style="font-family:Verdana; font-size:12px;");   Formular.document.write(" color:black; background:white;">");   var m = "";   for (var i = 0; i <= 6; i++) /* Formularfelder 0 - 6 */   {     var z = ""; var cr = 0;     for (var y = 0; y < Number(t[i].length); y++)     {       switch(t[i].charCodeAt(y))       {         case 13: z = z + "¦"; cr = 1; break;         case 10: if (!cr) z = z + "¦"; break;         case 32: z = z + "&#32;"; break;         case 34: z = z + "&#34;"; break;         case 37: z = z + "&#37;"; break;         case 38: z = z + "&#38;"; break;         case 60: z = z + "&#60;"; break;         case 62: z = z + "&#62;"; break;         case 63: z = z + "&#63;"; break;         case 64: z = z + "&#64;"; break;         case 196: z = z + "&#196;"; break;         case 214: z = z + "&#214;"; break;         case 220: z = z + "&#220;"; break;         case 223: z = z + "&#223;"; break;         case 228: z = z + "&#228;"; break;         case 246: z = z + "&#246;"; break;         case 252: z = z + "&#252;"; break;         case 8364: z = z + "EUR"; break;         default:         if (t[i].charCodeAt(y) > 32 && t[i].charCodeAt(y) < 127)           z = z + t[i].charAt(y);         else z = z + "&#191;";         break;       }     }     t[i] = z; z = "";     for (y = 0; y < Number(t[i].length); y++)     {       if (t[i].charAt(y) == "¦") z = z + "<br/>";       else z = z + t[i].charAt(y);     }     Formular.document.write(z + "<br/>");     z = "";     for (y = 0; y < Number(t[i].length); y++)     {       if (t[i].charAt(y) == "¦") z = z + "%0D%0A";       else z = z + t[i].charAt(y);     }     //if (i == 1) Formular.document.write("<a href="mailto:" + wert[1] +"">" + wert[1] + "</a>");     t[i] = z;     if (i >= 0) m = m + t[i] + "%0D%0A";     if (i <= 6) Formular.document.write("<br/>"); m = m + "%0D%0A";

}   //START Auswertung   Formular.document.write("<br/><b>Aufgrund Ihrer Angaben zu einem Produkt aus dem Bereich " + wert[3] + ", " + wert[4] + "

müssen folgende Faktoren berücksichtigt werden:</b>\n");

//ENDE Auswertung   Formular.document.write("<br/><b>Sie können dieses Formular vor dem Absenden ausdrucken. Sollten Sie weitere Fragen haben,

bitte wenden Sie sich an: <a href="mailto:jemand@email.com">jemand@email.com</a></b>");

/Formular.document.write("<br/><b>Test: </b>" + docForm.Unterkategorie.options[0].value);     Formular.document.write("<br/><b>Test: </b>" + docForm.Unterkategorie.options[1].value);       Formular.document.write("<br/><b>Test: </b>" + docForm.Unterkategorie.options[2].value);         Formular.document.write("<br/><b>Test: </b>" + docForm.Unterkategorie.options[3].value);/

Formular.document.write("<br/><br/><a href="mailto:" + email);   Formular.document.write("?subject=BETREFF" + "&body=" + m + """);   Formular.document.write(" onclick="window.setTimeout('self.close()',100)"");   Formular.document.write(">eMail versenden</a> ");   Formular.document.write("<a href=javascript:self.print();>Drucken</a>");   Formular.document.writeln("</body></html>");   Formular.document.close();   return false; } //--> </script>

</body>

</html>