Jag håller på att göra en sida för bokning av personal vid arrangemang.Visa och gömma div...
Man börjar på showSchema.asp, där alla arrangemang listas.
På varje arrangemang finns ett "+" tecken som innehåller följande kod:
<img src="common/img/expand.gif" width="9" height="9" onclick="schemaDetails('<%=(rsSchema.Fields.Item("id").Value)%>')" />
Denna kod aktiverar ett ajax-script som hämtar ut specifika detaljer för just det arrangemanget och visar det i en ny div. (<div id="schemaDetails"></div>)
Så här långt funkar allt!
Problemet uppstår när jag, i den detaljerade tabellen, försöker gömma div:en igen med hjälp av ett "-"-tecken.
Det funkar inte alls... och jag har helt kört fast, jag vet inte hur jag ska gå vidare nu.
Jag har hittat ett annat javascript som på något sätt ska kunna lösa det, men jag förstår mig inte på det.
showSchema.asp:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/oConn.asp" -->
<%
Dim rsSchema
Dim rsSchema_numRows
Set rsSchema = Server.CreateObject("ADODB.Recordset")
rsSchema.ActiveConnection = MM_oConn_STRING
rsSchema.Source = "SELECT * FROM ordningsvakterna_se.schema_arrangemang ORDER BY arrStart ASC"
rsSchema.CursorType = 0
rsSchema.CursorLocation = 2
rsSchema.LockType = 1
rsSchema.Open()
rsSchema_numRows = 0
%>
<%
Dim rsSchemaDetails__MMColParam
rsSchemaDetails__MMColParam = "1"
If (Request.Form("arr_id") <> "") Then
rsSchemaDetails__MMColParam = Request.Form("arr_id")
End If
%>
<%
Dim rsSchemaDetails
Dim rsSchemaDetails_numRows
Set rsSchemaDetails = Server.CreateObject("ADODB.Recordset")
rsSchemaDetails.ActiveConnection = MM_oConn_STRING
rsSchemaDetails.Source = "SELECT * FROM ordningsvakterna_se.schema_pass WHERE arr_id = " + Replace(rsSchemaDetails__MMColParam, "'", "''") + ""
rsSchemaDetails.CursorType = 0
rsSchemaDetails.CursorLocation = 2
rsSchemaDetails.LockType = 1
rsSchemaDetails.Open()
rsSchemaDetails_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
rsSchema_numRows = rsSchema_numRows + Repeat1__numRows
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Visa Schemat</title>
<link href="common/css/main.css" rel="stylesheet" type="text/css" />
<script src="schemaDetails.js"></script>
</head>
<body>
<table width="80%" border="0" cellpadding="0" cellspacing="0" class="schemaTable">
<tr>
<td class="loginTableTextBold" width="4"> </td>
<td width="9" class="loginTableTextBold"> </td>
<td width="116" class="loginTableTextBold">Namn:</td>
<td width="112" class="loginTableTextBold">Plats: </td>
<td width="81" class="loginTableTextBold">StartDatum:</td>
<td width="58" class="loginTableTextBold">StartTid:</td>
<td width="51" class="loginTableTextBold">SlutTid:</td>
<td width="55" class="loginTableTextBold">Timmar:</td>
<td class="loginTableTextBold">Antal Vakter: </td>
<td class="loginTableTextBold">Lediga Pass: </td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsSchema.EOF))
Dim startDatum
Dim slutDatum
Dim startTid
Dim slutTid
startDatum = Left(rsSchema.Fields.Item("arrStart").Value, 10)
slutDatum = Left(rsSchema.Fields.Item("arrSlut").Value, 10)
startTid = Mid(rsSchema.Fields.Item("arrStart").Value, 11,6)
slutTid = Mid(rsSchema.Fields.Item("arrSlut").Value, 11,6)
%>
<form>
<tr>
<td class="loginTableText" width="4"> </td>
<td class="loginTableText"><img src="common/img/expand.gif" width="9" height="9" onclick="schemaDetails('<%=(rsSchema.Fields.Item("id").Value)%>')" /></td>
<td class="loginTableText"><%=(rsSchema.Fields.Item("namn").Value)%></td>
<td class="loginTableText"><%=(rsSchema.Fields.Item("plats").Value)%></td>
<td class="loginTableText"><%= startDatum %></td>
<td class="loginTableText"><%= startTid %></td>
<td class="loginTableText"><%= slutTid %></td>
<td class="loginTableText">
<%
timmar = datediff("n",rsSchema.Fields.Item("arrStart").Value,rsSchema.Fields.Item("arrSlut").Value)
timmar = timmar/60
response.Write(timmar)
%>
</td>
<td width="176" class="loginTableText"><%=(rsSchema.Fields.Item("antalVakter").Value)%></td>
<td width="86" class="loginTableText"><%
antalObokade = rsSchema.Fields.Item("antalVakter").Value - rsSchema.Fields.Item("antalVakterBokade").Value
if antalObokade = 0 Then
response.Write("Inga lediga pass")
Else
response.Write(antalObokade)
End If
%> </td>
</tr></form>
<div id="schemaDetails"></div>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsSchema.MoveNext()
Wend
%>
</table>
</body>
</html>
<%
rsSchema.Close()
Set rsSchema = Nothing
%>
<%
rsSchemaDetails.Close()
Set rsSchemaDetails = Nothing
%>
schemaDetails.asp:
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/oConn.asp" -->
<%
Dim rsSchemaDetails__MMColParam
rsSchemaDetails__MMColParam = "1"
If (Request.QueryString("arr_id") <> "") Then
rsSchemaDetails__MMColParam = Request.QueryString("arr_id")
End If
%>
<%
Dim rsSchemaDetails
Dim rsSchemaDetails_numRows
Set rsSchemaDetails = Server.CreateObject("ADODB.Recordset")
rsSchemaDetails.ActiveConnection = MM_oConn_STRING
rsSchemaDetails.Source = "SELECT * FROM ordningsvakterna_se.schema_pass WHERE arr_id = " + Replace(rsSchemaDetails__MMColParam, "'", "''") + ""
rsSchemaDetails.CursorType = 0
rsSchemaDetails.CursorLocation = 2
rsSchemaDetails.LockType = 1
rsSchemaDetails.Open()
rsSchemaDetails_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
rsSchemaDetails_numRows = rsSchemaDetails_numRows + Repeat1__numRows
%>
<link href="common/css/main.css" rel="stylesheet" type="text/css" />
<table width="400" border="0" cellpadding="0" cellspacing="0" class="schemaDetailsTable">
<tr>
<td class="loginTableTextBold" width="20px">
</td>
<td class="loginTableTextBold">
<img src="common/img/contract.gif" width="9" height="9" onclick="togglemenu(schemaDetails)"/>
</td>
<td class="loginTableTextBold">
Namn:
</td>
<td class="loginTableTextBold">
Start:
</td>
<td class="loginTableTextBold">
Slut:
</td>
<td class="loginTableTextBold">
# Timmar
</td>
<td class="loginTableTextBold">
</td>
</tr>
<%
While ((Repeat1__numRows <> 0) AND (NOT rsSchemaDetails.EOF))
Dim startDatum
Dim slutDatum
Dim startTid
Dim slutTid
startTid = Mid(rsSchemaDetails.Fields.Item("start").Value, 11,6)
slutTid = Mid(rsSchemaDetails.Fields.Item("slut").Value, 11,6)
%>
<tr>
<td class="loginTableText" width="20px">
</td>
<td class="loginTableText">
</td>
<td class="loginTableText">
<% If (rsSchemaDetails.Fields.Item("passStatus").Value) = 0 Then %>
">Boka Pass
<% Else %>
<%=(rsSchemaDetails.Fields.Item("username").Value)%>
<% End If %>
</td>
<td class="loginTableText">
<%= startTid%>
</td>
<td class="loginTableText">
<%= slutTid%>
</td>
<td class="loginTableText">
</td>
<td class="loginTableText">
</td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
rsSchemaDetails.MoveNext()
Wend
%>
</table>
<%
rsSchemaDetails.Close()
Set rsSchemaDetails = Nothing
%>
//funktioner för ajax-biten.
var xmlHttp
function schemaDetails(str) {
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="schemaDetails.asp";
url=url+"?arr_id="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
//togglemenu(schemaDetails)
showID(schemaDetails);
}
function stateChanged()
{
if (xmlHttp.readyState==4)
{
document.getElementById("schemaDetails").innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
// funktioner för att visa/gömma detaljer.
function togglemenu(item) {
if (document.getElementById(item).style.visibility != 'visible') {
showID(item);
} else {
hideID(item);
}
}
function showID(item) {
document.getElementById(item).style.visibility = 'visible';
document.getElementById(item).style.display = 'block';
}
function hideID(item) {
document.getElementById(item).style.visibility = 'hidden';
document.getElementById(item).style.display = 'none';
}