Javascript kontrollere ikke formfelt
Hvorfor kontrollere javascriptet ikke om formfeltet navn og kommentar er udfyldt, når der trykkes på submit<%
' Databaseforbindelse - husk at angive sti til din database
Set Conn = Server.CreateObject("ADODB.Connection")
DSN = "DRIVER={Microsoft Access Driver (*.mdb)}; "
DSN = DSN & "DBQ=" & Server.MapPath ("guest.mdb")
Conn.Open DSN
strSQL = "Select * from jwgbog"
set rscount = conn.execute("select count(id) as antal from jwgbog")
antal = rscount("antal")
set rscount = nothing
%>
<html>
<head>
<title>Tomoe's gæstebog</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function CheckForm () {
var errorMsg = "";
//Check navn
if (document.newtag.navn.value == ""){
errorMsg += "\n\tNavn \t\t- Skriv dit navn";
}
//Check kommentar
if (document.newtag.kommentare.value == ""){
errorMsg += "\n\tKommentar \t- Skriv en Kommentar";
}
//Fejlbeskrivelse
if ((errorMsg != "")){
msg = "_________________________________________________\n\n";
msg += "Din besked er ikke blevet tilføjet pga. fejl i formularen.\n";
msg += "De skal rettes før du kan fortsætte!\n";
msg += "_________________________________________________\n\n";
msg += "Der blev fundet følgende fejl:\n";
errorMsg += alert(msg + errorMsg);
return false;
}
if (errorMsg == 0) {
document.newtag.submitbutton.disabled = true;
}
return true;
}
// -->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#006699" vlink="#006699" alink="#006699" background="../../images/baggrund3.gif" bgproperties="fixed">
<table border="0" width="500" bgcolor="#000000" cellspacing="1" cellpadding="0" align="center">
<tr>
<td width="100%" bgcolor="#FFFFFF" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr bgcolor="#FFFFFF">
<td width="50%"><div align="center"><font size="5"><b><font face="Verdana, Arial, Helvetica, sans-serif">Tomoe's
gæstebog </font></b></font></div></td>
</tr>
</table>
</td>
</tr>
</table>
<table border='0' cellspacing='0' cellpadding='0' width='500' align="center" height="19">
<tr>
<td width='1' valign='top' bgcolor='#000000'><img src="images/intet.gif" width='1'></td>
<td width='500' valign='top' bgcolor='#f7f7f7'>
<table width="100%" border="0" cellspacing="4" cellpadding="0">
<tr>
<td width="52%">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>
<a href="add.asp">Tilføj</a>
| <a href="guestbook.asp">Vis Gæstebogen</a>
| <a href="admin/login.asp" target="_self">Admin </a>
| </b></font></td>
<td width="48%">
<div align="right"><b><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Antal
meddelser i gæstbog: <b><%=antal%></b></font> <font face="Verdana, Arial, Helvetica, sans-serif" size="1"></font></b></div>
</td>
</tr>
</table>
</td>
<td width='1' valign='top' bgcolor='#000000'><img src="images/intet.gif" width='1'></td>
</tr>
</table>
<table border="0" width="500" bgcolor="#000000" cellspacing="1" cellpadding="0" align="center">
<tr>
<td bgcolor="#FFFFFF" valign="top" colspan="2">
<div align="center">
<% mode = request("mode") %>
<%
Const adOpenKeyset = 1
Const adLockOptimistic = 3
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "PROVIDER=MSDASQL;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("guest.mdb") & ";UID=admin;PWD=;"
Set rs = Server.CreateObject("ADODB.RecordSet")
strSQL = "Select * From jwgbog"
rs.Open strSQL, Conn, adOpenKeyset, adLockOptimistic
%>
<br>
<% if mode ="" then %>
<form action="add.asp?mode=tilfojet&action=submit" method="post" NAME="newtag" onSubmit="return CheckForm();">
<center>
<font face=tahoma size=2>
<div align="center">
<table width="400" border="0" cellspacing="1" cellpadding="3" class="bottom" align="center" bgcolor="#f7f7f7">
<tr>
<td width="180"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
Navn <span class="rot"> <font color="#FF0000">*</font></span></font><br>
<input type="text" name="navn" maxlength="100" class="bottom" size="30">
</td>
<td width="180"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
Bedøm site <span class="rot"></font> <br>
<SELECT NAME="pic">
<option selected value="">Ikke bedømt</option>
<OPTION value="5">5 stjerner (kanon site)</option>
<OPTION value="4">4 stjerner</option>
<OPTION value="3">3 stjerner</option>
<OPTION value="2">2 stjerner</option>
<OPTION value="1">1 stjerne (dårligt site)</option>
</SELECT>
</TD>
</tr>
<tr>
<td colspan="2" height="167"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">
Kommetar<span class="rot"><font color="#FFFFFF"> <font color="#FF0000">*</font></font></span><font color="#FF0000">
</font></font><font color="#FF0000"><br>
</font>
<textarea name="kommetare" cols="50" rows="8" class="bottom"></textarea>
</td>
</tr>
<tr>
<td width="134"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Email<span class="rot">
</span></font><span class="rot"><br>
<input type="text" name="email" maxlength="100" class="bottom" size="30">
</span></td>
<td width="251"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Hjemmeside</font><span class="rot"><font face="Verdana, Arial, Helvetica, sans-serif"><br>
<input type="text" name="url" maxlength="100" class="bottom" size="32">
</font></span></td>
</tr>
<tr>
<td colspan="2"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><span class="rot">
</span></font>
<table border="0" cellspacing="0" cellpadding="0" width="200">
<tr>
<td align="left">
<div align="left"><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><span class="rot">
<font color="#FF0000">*</font></span><font color="#666666">
= Skal indtastes</font></font></div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<b><font size="2" face="Verdana, Arial, Helvetica, sans-serif" class="mehr_platz">
</font></b> <br>
<table border="0" cellspacing="0" cellpadding="0" width="400">
<tr>
<td>
<div align="center"><font face="Verdana, Arial, Helvetica, sans-serif"><b>
<input type="Submit" value="Tilføj" name="submitbutton">
<input type="Reset" value="Slet Alt" name="Reset">
</b></font></div>
</td>
</tr>
</table>
<br>
</div>
</font>
</center>
<br>
</form>
<% end if %>
<% if mode ="tilfojet" then
rs.AddNew
rs("navn") = Request.form("navn")
rs("email") = Request.form("email")
rs("pic") = Request.form("pic")
rs("url") = Request.form("url")
rs("kommetare") = Request.form("kommetare")
rs("dato") = date()
rs("kl") = time()
rs("Ip") = Request.ServerVariables("REMOTE_ADDR")
rs.Update
%>
<p class="menuoverskrift2">Tak for din kommetar.</p>
<p><span class="skriftype"></span><br>
<br>
<% end if %></p></div>
</td>
</tr>
</table>
</body>
</html>