Ga naar inhoud

Controleren van velden in formulier doormiddel van Javascipt


anoniem

Aanbevolen berichten

Hallo, Ik heb een javascript gemaakt die mijn velden in een formulier controleerd of deze zijn ingevuld. Het controleren gaat goed, Alleen het versturen van het formulier gaat niet. Waar zit de fout? <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body { background-color: #FFFFA8; scrollbar-face-color:#FFFFA8; scrollbar-arrow-color:black; scrollbar-track-color:#FFFFA8; scrollbar-shadow-color:black; scrollbar-highlight-color:black; scrollbar-3dlight-color:''; scrollbar-darkshadow-Color:black; background-image: url(images/KLAPPER%20LOGO%20VOLTOOID.gif); background-repeat:no-repeat; background-position:center center; } .style1 { font-family: "Bookman Old Style"; font-size: 14px; } .style2 {color: #000000} --> </style></head> <body> <script language="JavaScript"> <!-- function formCheck(formobj){ // Enter name of mandatory fields var fieldRequired = Array("Naam", "Adres", "Postcode", "Woonplaats", "Telefoon", "E-mail", "Info", "Reactie"); // Enter field description to appear in the dialog box var fieldDescription = Array("Naam", "Adres", "Postcode", "Woonplaats", "Telefoon", "E-mail", "Info", "Reactie"); // dialog message var alertMsg = "Vul de volgende velden in om het formulier te kunnen verzenden: \n"; var l_Msg = alertMsg.length; for (var i = 0; i < fieldRequired.length; i++){ var obj = formobj.elements[fieldRequired[i]]; if (obj){ switch(obj.type){ case "select-one": if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "select-multiple": if (obj.selectedIndex == -1){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "text": case "textarea": if (obj.value == "" || obj.value == null){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; default: } if (obj.type == undefined){ var blnchecked = false; for (var j = 0; j < obj.length; j++){ if (obj[j].checked){ blnchecked = true; } } if (!blnchecked){ alertMsg += " - " + fieldDescription[i] + "\n"; } } } } if (alertMsg.length == l_Msg){ return true; }else{ alert(alertMsg); return false; } } // --> </script> <form name="ch-formulier" onsubmit="return formCheck(this);"> <form action="[b:202c69b77e]<mailserver>[/b:202c69b77e]" method="post"> <input type="Hidden" name="E-MAIL" value="[b:202c69b77e]<afzender mail adres>[/b:202c69b77e]"> <input type="Hidden" name="LOAD-URL" value="bedanktinfo.htm"> <input type="Hidden" name="SUBJECT" value="Informatie/ aanvraag"> <input type="Hidden" name="SENDER" value="[b:202c69b77e]<Sender>[/b:202c69b77e]"> </span> </p> <p class="style1"> <strong>Uw gegevens:</strong></p> <table width="497"> <tr> <td width="186" class="style1">Naam</td> <td width="50" class="style1">&nbsp;</td> <td width="245" class="style1"> <input name="Naam" type="text" id="Naam"> </td> </tr> <tr> <td class="style1">Adres</td> <td width="50" class="style1">&nbsp;</td> <td class="style1"> <input name="Adres" type="text" id="Adres"> </td> </tr> <tr> <td class="style1">Postcode</td> <td width="50" class="style1">&nbsp;</td> <td class="style1"> <input name="Postcode" type="text" id="Postcode"> </td> </tr> <tr> <td class="style1">Woonplaats</td> <td width="50" class="style1">&nbsp;</td> <td class="style1"> <input name="Woonplaats" type="text" id="Woonplaats"> </td> </tr> <tr> <td class="style1">Telefoonnummer</td> <td width="50" class="style1">&nbsp;</td> <td class="style1"> <input name="Telefoon" type="text" id="Telefoon"> </td> </tr> <tr> <td class="style1">E-mail adres </td> <td class="style1">&nbsp;</td> <td class="style1"> <input name="E-mail" type="text" id="E-mail"> </td> </tr> <tr> <td class="style1">&nbsp;</td> <td class="style1">&nbsp;</td> <td class="style1">&nbsp;</td> </tr> <tr> <td class="style1"><p>Selecteer hier waar u meer informatie overwilt hebben.</p> <p>(Hou de <strong>Ctrl</strong> toets in om meerdere opties te selecteren)</p></td> <td class="style1">&nbsp;</td> <td class="style1"><select name="Info" size="6" multiple id="Info"> <option>Champagne-ontbijt</option> <option>Diner Catering</option> <option>Luch Catering</option> <option>Sat&eacute;kraam</option> <option>Barbecue</option> <option>Eetcafe</option> </select></td> </tr> <tr> <td class="style1">&nbsp;</td> <td class="style1">&nbsp;</td> <td class="style1">&nbsp;</td> </tr> <tr> <td class="style1">Hier kunt u uw vragen en/ of opmerkingen kwijt. </td> <td class="style1">&nbsp;</td> <td class="style1"><textarea name="Vragen en Reactie" rows="8" id="Vragen en Reactie"></textarea></td> </tr> </table> <table width="497"> <tr> <td class="style1"><form name="form1" method="post" action=""> <input name="Verzenden" type="submit" id="Verzenden4" value="Verzenden"> <input name="Leeg" type="reset" id="Leeg4" value="Leeg"> </form></td> <td class="style1">&nbsp;</td> <td class="style1">&nbsp;</td> </tr> </table> <p class="style1">&nbsp;</p> <p class="style1">&nbsp;</p> </body> </html> Groeten, Daniël Bolt PS: de vetgedrukte gegevens heb ik veranderd, ik heb hiervan de juiste gegevens.
Link naar reactie
Je hebt er meerder form tags in staan welke niet goed zijn afgesloten. De <mailserver> moet verwijzen naar een formprocessor (een script op de server bijvoorbeeld cgi-bin/form.cgi o.i.d. mail.provider.nl zal dus nooit werken. [code:1:51d6309c84] <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <style type="text/css"> <!-- body { background-color: #FFFFA8; scrollbar-face-color:#FFFFA8; scrollbar-arrow-color:black; scrollbar-track-color:#FFFFA8; scrollbar-shadow-color:black; scrollbar-highlight-color:black; scrollbar-3dlight-color:''; scrollbar-darkshadow-Color:black; background-image: url(images/KLAPPER%20LOGO%20VOLTOOID.gif); background-repeat:no-repeat; background-position:center center; } .style1 { font-family: "Bookman Old Style"; font-size: 14px; } .style2 {color: #000000} --> </style></head> <body> <script language="JavaScript"> <!-- function formCheck(formobj){ // Enter name of mandatory fields var fieldRequired = Array("Naam", "Adres", "Postcode", "Woonplaats", "Telefoon", "E-mail", "Info", "Reactie"); // Enter field description to appear in the dialog box var fieldDescription = Array("Naam", "Adres", "Postcode", "Woonplaats", "Telefoon", "E-mail", "Info", "Reactie"); // dialog message var alertMsg = "Vul de volgende velden in om het formulier te kunnen verzenden: \n"; var l_Msg = alertMsg.length; for (var i = 0; i < fieldRequired.length; i++){ var obj = formobj.elements[fieldRequired[i]]; if (obj){ switch(obj.type){ case "select-one": if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "select-multiple": if (obj.selectedIndex == -1){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "text": case "textarea": if (obj.value == "" || obj.value == null){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; default: } if (obj.type == undefined){ var blnchecked = false; for (var j = 0; j < obj.length; j++){ if (obj[j].checked){ blnchecked = true; } } if (!blnchecked){ alertMsg += " - " + fieldDescription[i] + "\n"; } } } } if (alertMsg.length == l_Msg){ return true; }else{ alert(alertMsg); return false; } } // --> </script> <form name="ch-formulier" onsubmit="return formCheck(this);" action="<mailserver>" method="post"> <input type="Hidden" name="E-MAIL" value="<afzender mail adres>"> <input type="Hidden" name="LOAD-URL" value="bedanktinfo.htm"> <input type="Hidden" name="SUBJECT" value="Informatie/ aanvraag"> <input type="Hidden" name="SENDER" value="<Sender>"> <p class="style1"> <strong>Uw gegevens:</strong></p> <table width="497"> <tr> <td width="186" class="style1">Naam</td> <td width="50" class="style1">&nbsp;</td> <td width="245" class="style1"> <input name="Naam" type="text" id="Naam"> </td> </tr> <tr> <td class="style1">Adres</td> <td width="50" class="style1">&nbsp;</td> <td class="style1"> <input name="Adres" type="text" id="Adres"> </td> </tr> <tr> <td class="style1">Postcode</td> <td width="50" class="style1">&nbsp;</td> <td class="style1"> <input name="Postcode" type="text" id="Postcode"> </td> </tr> <tr> <td class="style1">Woonplaats</td> <td width="50" class="style1">&nbsp;</td> <td class="style1"> <input name="Woonplaats" type="text" id="Woonplaats"> </td> </tr> <tr> <td class="style1">Telefoonnummer</td> <td width="50" class="style1">&nbsp;</td> <td class="style1"> <input name="Telefoon" type="text" id="Telefoon"> </td> </tr> <tr> <td class="style1">E-mail adres </td> <td class="style1">&nbsp;</td> <td class="style1"> <input name="E-mail" type="text" id="E-mail"> </td> </tr> <tr> <td class="style1">&nbsp;</td> <td class="style1">&nbsp;</td> <td class="style1">&nbsp;</td> </tr> <tr> <td class="style1"><p>Selecteer hier waar u meer informatie overwilt hebben.</p> <p>(Hou de <strong>Ctrl</strong> toets in om meerdere opties te selecteren)</p></td> <td class="style1">&nbsp;</td> <td class="style1"><select name="Info" size="6" multiple id="Info"> <option>Champagne-ontbijt</option> <option>Diner Catering</option> <option>Luch Catering</option> <option>Sat&eacute;kraam</option> <option>Barbecue</option> <option>Eetcafe</option> </select></td> </tr> <tr> <td class="style1">&nbsp;</td> <td class="style1">&nbsp;</td> <td class="style1">&nbsp;</td> </tr> <tr> <td class="style1">Hier kunt u uw vragen en/ of opmerkingen kwijt. </td> <td class="style1">&nbsp;</td> <td class="style1"><textarea name="Vragen en Reactie" rows="8" id="Vragen en Reactie"></textarea></td> </tr> </table> <table width="497"> <tr> <td class="style1"> <input name="Verzenden" type="submit" id="Verzenden4" value="Verzenden"> <input name="Leeg" type="reset" id="Leeg4" value="Leeg"> </td> <td class="style1">&nbsp;</td> <td class="style1">&nbsp;</td> </tr> </table> </form> <p class="style1">&nbsp;</p> <p class="style1">&nbsp;</p> </body> </html> [/code:1:51d6309c84]
Link naar reactie

Om een reactie te plaatsen, moet je eerst inloggen

Gast
Reageer op dit topic

×   Geplakt als verrijkte tekst.   Herstel opmaak

  Er zijn maximaal 75 emoji toegestaan.

×   Je link werd automatisch ingevoegd.   Tonen als normale link

×   Je vorige inhoud werd hersteld.   Leeg de tekstverwerker

×   Je kunt afbeeldingen niet direct plakken. Upload of voeg afbeeldingen vanaf een URL in

×
×
  • Nieuwe aanmaken...