08. juli 2002 - 12:01
Der er
10 kommentarer og 3 løsninger
Ikke sende form, før indtast af nødvendige data
Hej Eksperter Jeg har en form der gør det, at den sender indtastede data til min e-mail. Men jeg skal have fundet ud af, hvordan jeg gør det sådan, at man ikke kan sende det, før der er indtastet noget i alle felterne, samt en gyldig e-mail adresse. Hvordan gør jeg det? Min kode ser således ud: <html> <head> </head> <body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0"> <table border="0" cellpadding="0" cellspacing="0" width="540"> <tr> <td valign="top" height="12" width="540"></td> </tr> <tr> <td width="540"> <form method="POST" action="--WEBBOT-SELF--"> <!--webbot bot="SaveResults" s-email-format="HTML/BR" s-email-address="xxx@xxx.dk" b-email-label-fields="TRUE" b-email-replyto-from-field="FALSE" s-email-replyto="email2" b-email-subject-from-field="FALSE" s-email-subject="Formular: Indstiller personen..." s-date-format="%A den %d. %B %Y" s-time-format="%H:%M" s-builtin-fields="Date Time" u-confirmation-url="bekraeft.htm" startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--webbot bot="SaveResults" endspan i-checksum="43374" --><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="AutoNumber3"> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12"> </td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> </td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12"><b>Vej holder på: ></b></td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="jeg_indstiller" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">fra by:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="fra_selskab" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">adresse:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="postadr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Telefonnummer:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="tlfnr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">E-mail adresse:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="email" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Han/Hun skal have prisen fordi:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <textarea rows="14" name="fordi" cols="44" style="border: 1px solid #000000"></textarea></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Mit navn:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_navn" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Mit lønnummer:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_loennr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Mit selskab:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_selskab" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Min organisatoriske enhed:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_orgenhed" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Min interne postadresse:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_postadr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Mit telefonnummer:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_tlfnr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Min E-mail adresse:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_email" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" bgcolor="#CCCCCC" style="padding-left: 3"> </td> <td width="62%" style="text-align: center" valign="top" bgcolor="#CCCCCC"> <input type="reset" value="Forefra" name="clear" style="border: 1px solid #000000; padding: 0"> <input type="submit" value="Indsend" name="send" style="border: 1px solid #000000"></td> </tr> <tr> <td width="38%" bgcolor="#CCCCCC" style="padding-left: 3"> </td> <td width="62%" style="text-align: center" valign="top" bgcolor="#CCCCCC"> </td> </tr> </table> <p> </p> </form> <p> </td> </tr> </table> </div> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; background-image:url('../images/baggrunde/crisback_small.jpg'); background-repeat:no-repeat" width="539" id="AutoNumber2" background="images/crisback_small.jpg"> <tr> <td width="538"><p style="text-align: right"><b><font size="1"><font color="#808080" face="Verdana">Opdateret for TDC Services <br> af IT-Divisionen </font><a href="mailto:sit-intra@tdc.dk" style="text-decoration: none; "><font face="Verdana" size="1">Intranet Redaktion</font></a><font color="#808080" face="Verdana"><br> Sidst opdateret: <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d. %B %Y" --></font></font></b></td> </tr> </table> </body></html> Nu sender den uanset om der er indtastet noget eller ej. Man kan sådan set bare trykke på Send og så sender den. Mona
Annonceindlæg fra Infor
Og ja, jeg er praktikant på tdc, hvis i kan tyde det ud fra koden. Ved der er nogle der kunne finde på at kommentere det...*gg*
Og jeg har kun frontpage at lave det i...
i dit form-tak indsætter du følgende; onSubmit="return Checkform(this);" og mellem <head> og </head> skal du indsætte <script language="JavaScript"> function Checkform(thisform) { strError = 'Der opstod følgende fejl:\n\n'; intError = 0; if (thisform.XXXXX.value == ""){ intError = 1; strError = strError + '- YYYYYY skal udfyldes\n' thisform.XXXXX.focus(); } if (intError == 1) { alert(strError) return false; } } </script> der hvor der står XXXXX skal du indsætte navnet på dit inputfelt - og i YYYYY kan du skrive det der nu svarer til "overskriften" på inputfeltet. de fem linier hvoraf den første starter med "if" skal du kopiere en gang for hver input-felt du har - og så bare huske at ændre XXXXX og YYYYY
Du kan bruge den her : <html> <script> fejl = false; function validerDu(hvad){ var emailFilter=/^.+@.+\..{2,3}$/; var mailDu = document.forms[0].elements["indsenders_email"].value for (i =0;i<document.forms[0].length;i++){ if(document.forms[0].elements[i].value == ""){ fejl = true alert(document.forms[0].elements[i].name) return false }else if (!(emailFilter.test(mailDu))) { fejl = true return false } else { var fy= /[\(\)\<\>\,\;\:\\\"\[\]]/ if (mailDu.match(fy)) { fejl = true return false } } } if(!fejl){ return true; } } </script> <head> </head> <body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0"> <table border="0" cellpadding="0" cellspacing="0" width="540"> <tr> <td valign="top" height="12" width="540"></td> </tr> <tr> <td width="540"> <form method="POST" action="--WEBBOT-SELF--" onsubmit="return validerDu(this)"> <!--webbot bot="SaveResults" s-email-format="HTML/BR" s-email-address="xxx@xxx.dk" b-email-label-fields="TRUE" b-email-replyto-from-field="FALSE" s-email-replyto="email2" b-email-subject-from-field="FALSE" s-email-subject="Formular: Indstiller personen..." s-date-format="%A den %d. %B %Y" s-time-format="%H:%M" s-builtin-fields="Date Time" u-confirmation-url="bekraeft.htm" startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--webbot bot="SaveResults" endspan i-checksum="43374" --><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="AutoNumber3"> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12"> </td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> </td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12"><b>Vej holder på: ></b></td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="jeg_indstiller" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">fra by:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="fra_selskab" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">adresse:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="postadr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Telefonnummer:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="tlfnr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">E-mail adresse:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="email" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Han/Hun skal have prisen fordi:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <textarea rows="14" name="fordi" cols="44" style="border: 1px solid #000000"></textarea></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Mit navn:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_navn" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Mit lønnummer:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_loennr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Mit selskab:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_selskab" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Min organisatoriske enhed:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_orgenhed" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Min interne postadresse:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_postadr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Mit telefonnummer:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_tlfnr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Min E-mail adresse:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_email" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" bgcolor="#CCCCCC" style="padding-left: 3"> </td> <td width="62%" style="text-align: center" valign="top" bgcolor="#CCCCCC"> <input type="reset" value="Forefra" name="clear" style="border: 1px solid #000000; padding: 0"> <input type="submit" value="Indsend" name="send" style="border: 1px solid #000000"></td> </tr> <tr> <td width="38%" bgcolor="#CCCCCC" style="padding-left: 3"> </td> <td width="62%" style="text-align: center" valign="top" bgcolor="#CCCCCC"> </td> </tr> </table> <p> </p> </form> <p> </td> </tr> </table> </div> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; background-image:url('../images/baggrunde/crisback_small.jpg'); background-repeat:no-repeat" width="539" id="AutoNumber2" background="images/crisback_small.jpg"> <tr> <td width="538"><p style="text-align: right"><b><font size="1"><font color="#808080" face="Verdana">Opdateret for TDC Services <br> af IT-Divisionen </font><a href="mailto:sit-intra@tdc.dk" style="text-decoration: none; "><font face="Verdana" size="1">Intranet Redaktion</font></a><font color="#808080" face="Verdana"><br> Sidst opdateret: <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d. %B %Y" --></font></font></b></td> </tr> </table> </body></html>
Ingen af dem kan jeg få til at virke.
Min virker perfekt - Du skal bare copy/paste hele molevitten over...
Har prøvet, der sker ikke en disse...
Den skal jo helst sige, at der skal indtastes i felterne, den skal ikke bare stå og være dum (foretage sig ingenting) når man trykker send.
Det kan simpelthen ikke passe. Udfyldt du en rigtig email? Den tjekker for om formatet er korrekt, så der SKAL stå noget ala girl@sada.dk
08. juli 2002 - 12:32
#10
Jaja, jeg udfyldte den med min mail.
08. juli 2002 - 12:33
#11
Prøv den her så, den giver en alert, når du laver fejl : <html> <script> fejl = false; function validerDu(hvad){ var emailFilter=/^.+@.+\..{2,3}$/; var mailDu = document.forms[0].elements["indsenders_email"].value for (i =0;i<document.forms[0].length;i++){ if(document.forms[0].elements[i].value == ""){ fejl = true alert("Der er fejl i feltet: "+document.forms[0].elements[i].name) return false }else if (!(emailFilter.test(mailDu))) { alert("Der er fejl i emailfeltet") fejl = true return false } else { var fy= /[\(\)\<\>\,\;\:\\\"\[\]]/ if (mailDu.match(fy)) { alert("Der er fejl i emailfeltet") fejl = true return false } } } if(!fejl){ return true; } } </script> <head> </head> <body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0"> <table border="0" cellpadding="0" cellspacing="0" width="540"> <tr> <td valign="top" height="12" width="540"></td> </tr> <tr> <td width="540"> <form method="POST" action="--WEBBOT-SELF--" onsubmit="return validerDu(this)"> <!--webbot bot="SaveResults" s-email-format="HTML/BR" s-email-address="xxx@xxx.dk" b-email-label-fields="TRUE" b-email-replyto-from-field="FALSE" s-email-replyto="email2" b-email-subject-from-field="FALSE" s-email-subject="Formular: Indstiller personen..." s-date-format="%A den %d. %B %Y" s-time-format="%H:%M" s-builtin-fields="Date Time" u-confirmation-url="bekraeft.htm" startspan --><input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--webbot bot="SaveResults" endspan i-checksum="43374" --><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="AutoNumber3"> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12"> </td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> </td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12"><b>Vej holder på: ></b></td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="jeg_indstiller" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">fra by:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="fra_selskab" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">adresse:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="postadr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Telefonnummer:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="tlfnr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">E-mail adresse:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="email" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Han/Hun skal have prisen fordi:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <textarea rows="14" name="fordi" cols="44" style="border: 1px solid #000000"></textarea></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Mit navn:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_navn" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Mit lønnummer:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_loennr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Mit selskab:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_selskab" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Min organisatoriske enhed:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_orgenhed" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Min interne postadresse:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_postadr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Mit telefonnummer:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_tlfnr" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" valign="top" bgcolor="#CCCCCC" style="padding-left: 12">Min E-mail adresse:</td> <td width="62%" valign="top" style="text-align: center" bgcolor="#CCCCCC"> <input type="text" name="indsenders_email" size="44" style="border: 1px solid #000000; padding: 0"></td> </tr> <tr> <td width="38%" bgcolor="#CCCCCC" style="padding-left: 3"> </td> <td width="62%" style="text-align: center" valign="top" bgcolor="#CCCCCC"> <input type="reset" value="Forefra" name="clear" style="border: 1px solid #000000; padding: 0"> <input type="submit" value="Indsend" name="send" style="border: 1px solid #000000"></td> </tr> <tr> <td width="38%" bgcolor="#CCCCCC" style="padding-left: 3"> </td> <td width="62%" style="text-align: center" valign="top" bgcolor="#CCCCCC"> </td> </tr> </table> <p> </p> </form> <p> </td> </tr> </table> </div> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse; background-image:url('../images/baggrunde/crisback_small.jpg'); background-repeat:no-repeat" width="539" id="AutoNumber2" background="images/crisback_small.jpg"> <tr> <td width="538"><p style="text-align: right"><b><font size="1"><font color="#808080" face="Verdana">Opdateret for TDC Services <br> af IT-Divisionen </font><a href="mailto:sit-intra@tdc.dk" style="text-decoration: none; "><font face="Verdana" size="1">Intranet Redaktion</font></a><font color="#808080" face="Verdana"><br> Sidst opdateret: <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d. %B %Y" --></font></font></b></td> </tr> </table> </body></html>
08. juli 2002 - 12:54
#12
hos mig virker både min og den fra nikolajdu - den primære forskel er at min tjecker for hver enkelt felt og giver derfor fejlbesked enkeltvis - og så har jeg glemt at tjecke for email
08. juli 2002 - 12:57
#13
Jeg har fået hjælp fra en anden. Men jeg vil ikke spilde jeres tid, så i får hver 50 points...Undskyld.
Vi tilbyder markedets bedste kurser inden for webudvikling