djfenom
asked on
AJAX Toggle expand content in div
I'm trying to replicate this effect:
http://www.libraholidays.co.uk/forms/holidays1.asp?Action=Search&dbCode=L07&BrochureType=CY&depCode=LGW&HolidayType=IT%2ASH&FromDay=20&FromMonth=Dec+08&Accommodation=9402&arrCode=PFO&Resort=&Diff=0&NoAdults=2&NoChildren=0&NoInfants=0&Duration=7&Board=HB&SortBy=&PromoCode=
Click on the details and images button under the price, the box is then expanded and the details and images are loaded below.
I realise this is using AJAX, I just need a script where I can use a button to toggle viewing external content from another file.
Can anyone point me in the right direction??
Thanks
Chris
http://www.libraholidays.co.uk/forms/holidays1.asp?Action=Search&dbCode=L07&BrochureType=CY&depCode=LGW&HolidayType=IT%2ASH&FromDay=20&FromMonth=Dec+08&Accommodation=9402&arrCode=PFO&Resort=&Diff=0&NoAdults=2&NoChildren=0&NoInfants=0&Duration=7&Board=HB&SortBy=&PromoCode=
Click on the details and images button under the price, the box is then expanded and the details and images are loaded below.
I realise this is using AJAX, I just need a script where I can use a button to toggle viewing external content from another file.
Can anyone point me in the right direction??
Thanks
Chris
ASKER
I'm already using Jquery, so don't really want to use YUI.
How would I do this with Jquery?
How would I do this with Jquery?
Jquery - another great library: just as simple: Not tested but this should give you the idea:
Examples:
http://docs.jquery.com/Ajax
http://www.ibm.com/developerworks/library/x-ajaxjquery.html
Examples:
http://docs.jquery.com/Ajax
http://www.ibm.com/developerworks/library/x-ajaxjquery.html
$('details-button').click(function () {
$.post('DetailsIno.aspx',
success: function (o) {
var detailsInfo = o.responseText;
$('mainContent').innerHTML = detailslsInfo;
});
});
ASKER
Thanks for that. This is what I've got:
<script type="text/javascript" src="js/jquery.js"></scrip t>
<script type="text/javascript">
$('detail').click(function () {
$.post('lettings-detail.as p?id=<%=RS ("propID") %>',
success: function (o) {
var detailsInfo = o.responseText;
$('detail<%=RS("propID")%> ').innerHT ML = detailslsInfo;
});
});
</script>
<a href="#" class="detail">view details</a>
<div id="detail<%=RS("propID")% >"></div>
Is this right? I'm currently getting an error - Line 13 - expected )
Also how would I do it so that it toggles on and off when the button is pressed?
<script type="text/javascript" src="js/jquery.js"></scrip
<script type="text/javascript">
$('detail').click(function
$.post('lettings-detail.as
success: function (o) {
var detailsInfo = o.responseText;
$('detail<%=RS("propID")%>
});
});
</script>
<a href="#" class="detail">view details</a>
<div id="detail<%=RS("propID")%
Is this right? I'm currently getting an error - Line 13 - expected )
Also how would I do it so that it toggles on and off when the button is pressed?
ASKER
Anybody??
Sorry for the delayed Response - I had to set some fires out at work. Anyway, I am assuming you are doing something with asp when you wrote <%=RS("propID")%>, but I am not sure what you are trying to do there?
However the attached code snipped worked for me. I tested it out and worked fine.
However the attached code snipped worked for me. I tested it out and worked fine.
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(
function(){
$.post("Confirm.aspx?command=GetDetails",{
},function(txt){
var element = $('detailsInfo');
element.innerHTML = txt;
});
});
</script>
//aspx code
protected void Page_Load(object sender, EventArgs e)
{
string command = Request.QueryString["command"];
if (command == "GetDetails") {
getDetails();
}
}
private void getDetails()
{
string html = "<h1>This is the details info</h1>";
Response.Expires = -1;
Response.ContentType = "text/plain";
Response.Write(html);
Response.End();
}
ASKER
I'm using classic ASP, the part were I refer to lettings-detail.asp?id=<%= RS("propID ")%> is just a page that filters the content depending on the record.
I used <div id="detail<%=RS("propID")% >"></div> to get a unique div name each time.
I've tried your code and I'm still getting an error - Line 13 - expected )
I used <div id="detail<%=RS("propID")%
I've tried your code and I'm still getting an error - Line 13 - expected )
Hmm.. For testing purposes remove the <%=RS("propID")%> reference to see if that is causing the error.
<div id="detail"></div>
<div id="detail"></div>
$(document).ready(
var propID = document.getElementsByID('detail');
function(){
$.post("lettings-detail.asp?id=" + propID, {
},function(txt){
var element = $('detailsInfo');
element.innerHTML = txt;
});
});
ASKER
Ok, so now I've got this:
<script type="text/javascript">
$(document).ready(
var propID = document.getElementsByID(' detail');
function(){
$.post("lettings-detail.as p?id=" + propID, {
},function(txt){
var element = $('detailsInfo');
element.innerHTML = txt;
});
});
</script>
But I'm still getting an error, now on line 10?
The link to expand the text is <a href="#" class="detail">view details</a> and the div is <div id="detailsInfo"></div>, is this right? Where does the ID from the DB get passed?
<script type="text/javascript">
$(document).ready(
var propID = document.getElementsByID('
function(){
$.post("lettings-detail.as
},function(txt){
var element = $('detailsInfo');
element.innerHTML = txt;
});
});
</script>
But I'm still getting an error, now on line 10?
The link to expand the text is <a href="#" class="detail">view details</a> and the div is <div id="detailsInfo"></div>, is this right? Where does the ID from the DB get passed?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, thanks, this is what I originally had:
<script type="text/javascript" src="js/jquery.js"></scrip t>
<script type="text/javascript">
$('detail').click(function () {
$.post('lettings-detail.as p?id=<%=RS ("propID") %>',
success: function (o) {
var detailsInfo = o.responseText;
$('detail<%=RS("propID")%> ').innerHT ML = detailslsInfo;
});
});
</script>
<div id="rightcol">
<h2>Lettings</h2>
<p>
<% if RS.eof then %>
</p>
<p class="firstpara">Sorry there are no properties available that meet your search criteria.</p>
<p>Please <a href="javascript:history.b ack(1)">tr y again</a></p>
<% else %>
<% while not RS.eof %>
<% if RS("offline") = 0 then %>
<div class="propbox">
<% if (RS("image1").Value) = "no-image.jpg" then %>
<a href="lettings-display.asp ?id=<%=RS( "propID")% >"><img src="prop-images/thumb.jpg " width="138" height="108" border="0" alt="<%=RS("address")%>" /></a>
<% else %>
<a href="lettings-display.asp ?id=<%=RS( "propID")% >"><img src="prop-images/<%=RS("im age1")%>" alt="<%=RS("address")%>" width="138" height="108" border="0" /></a>
<% end if %>
<h3><%=RS("address")%></h3 >
<p><%=left (RS("description"),80)%>.. ..</p>
<ul>
<li><%=RS("beds")%> Bedroom</li>
<li><%= FormatCurrency((RS("rent") ), 0, -2, -2, -2) %> <%=RS("payTitle")% ></li>
<li class="nopad"><a href="#" class="detail">view details</a></li>
</ul>
<div class="cleaner"></div>
<div id="detail<%=RS("propID")% >"></div>
</div>
<% end if %>
<%
RS.movenext
wend
%>
<p><a href="lettings.asp"><< search again</a></p>
<% end if %>
</div>
My lettings-detail.asp page is as follows:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/maltings .asp" -->
<%
Dim RSresults__MMColParam
RSresults__MMColParam = "1"
If (Request.QueryString("id") <> "") Then
RSresults__MMColParam = Request.QueryString("id")
End If
%>
<%
Dim RSresults
Dim RSresults_numRows
Set RSresults = Server.CreateObject("ADODB .Recordset ")
RSresults.ActiveConnection = MM_maltings_STRING
RSresults.Source = "SELECT * FROM qrylettings WHERE propID = " + Replace(RSresults__MMColPa ram, "'", "''") + ""
RSresults.CursorType = 0
RSresults.CursorLocation = 2
RSresults.LockType = 1
RSresults.Open()
RSresults_numRows = 0
%>
<!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>Property Sales</title>
<link href="maltings.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<h3><%=(RSresults.Fields.I tem("addre ss").Value )%></h3>
<div id="propimg">
<% if request.querystring("img") = "" then %>
<p><img src="prop-images/<%=(RSres ults.Field s.Item("im age1").Val ue)%>" alt="<%=(RSresults.Fields. Item("addr ess").Valu e)%>" width="264" /></p>
<% else %>
<p><img src="prop-images/<%=(RSres ults.Field s.Item("im age2").Val ue)%>" alt="<%=(RSresults.Fields. Item("addr ess").Valu e)%>" width="264" /></p>
<% end if %>
</div>
<div id="propdetails">
<p><strong>Area: </strong><%=(RSresults.Fie lds.Item(" regionName ").Value)% > | <strong>Beds: </strong><%=(RSresults.Fie lds.Item(" beds").Val ue)%></p>
<p><strong>Property Type: </strong><%=(RSresults.Fie lds.Item(" proptype") .Value)%>< /p>
<p><strong>Price:</strong> <%= FormatCurrency((RSresults. Fields.Ite m("rent"). Value), 0, -2, -2, -2) %> <%=(RSresults.Fiel ds.Item("p ayTitle"). Value)%></ p>
<% if RSresults.Fields.Item("ref erence").V alue <> "" then %>
<p><strong>Property Reference: </strong>Property <%=(RSresults.Fields.Item( "reference ").Value)% ></p>
<% end if %>
<% if RSresults.Fields.Item("ima ge2").Valu e = "no-image.jpg" then %>
<% else %>
<% if request.querystring("img") = "" then %>
<p><strong>Images:</strong > 1 | <a href="lettings-display.asp ?id=<%=(RS results.Fi elds.Item( "propID"). Value)%>&a mp;img=<%= (RSresults .Fields.It em("image2 ").Value)% >" title="View Alternate Image">2</a></p>
<% else %>
<p><strong>Images:</strong > <a href="javascript:history.b ack(-1)" title="View Alternate Image">1</a> | 2</p>
<% end if %>
<% end if %>
<% if request.querystring("img") = "" then %>
<p><a href="mailto:info@mrc-prop erty.co.uk ?subject=M RC Property Request: <%=(RSresults.Fields.Item( "address") .Value)%>" class="request">Request Info</a> <a href="javascript:window.pr int()" class="print">Print Page</a></p>
<% else %>
<p><a href="mailto:info@mrc-prop erty.co.uk ?subject=M RC Property Request: <%=(RSresults.Fields.Item( "address") .Value)%>" class="request">Request Info</a> <a href="javascript:window.pr int()" class="print">Print Page</a></p>
<% end if %>
</div>
<p>
<% Response.Write Replace(RSresults.Fields.I tem("descr iption"), vbCrLf, "<br />")%>
</p>
<% if request.querystring("img") = "" then %>
<p><a href="javascript:history.b ack(-1)">< < Back to Results</a></p>
<% else %>
<p><a href="javascript:history.g o(-2)"><< Back to Results</a></p>
<% end if %>
</div>
</body>
</html>
<%
RSresults.Close()
Set RSresults = Nothing
%>
<script type="text/javascript" src="js/jquery.js"></scrip
<script type="text/javascript">
$('detail').click(function
$.post('lettings-detail.as
success: function (o) {
var detailsInfo = o.responseText;
$('detail<%=RS("propID")%>
});
});
</script>
<div id="rightcol">
<h2>Lettings</h2>
<p>
<% if RS.eof then %>
</p>
<p class="firstpara">Sorry there are no properties available that meet your search criteria.</p>
<p>Please <a href="javascript:history.b
<% else %>
<% while not RS.eof %>
<% if RS("offline") = 0 then %>
<div class="propbox">
<% if (RS("image1").Value) = "no-image.jpg" then %>
<a href="lettings-display.asp
<% else %>
<a href="lettings-display.asp
<% end if %>
<h3><%=RS("address")%></h3
<p><%=left (RS("description"),80)%>..
<ul>
<li><%=RS("beds")%> Bedroom</li>
<li><%= FormatCurrency((RS("rent")
<li class="nopad"><a href="#" class="detail">view details</a></li>
</ul>
<div class="cleaner"></div>
<div id="detail<%=RS("propID")%
</div>
<% end if %>
<%
RS.movenext
wend
%>
<p><a href="lettings.asp"><< search again</a></p>
<% end if %>
</div>
My lettings-detail.asp page is as follows:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/maltings
<%
Dim RSresults__MMColParam
RSresults__MMColParam = "1"
If (Request.QueryString("id")
RSresults__MMColParam = Request.QueryString("id")
End If
%>
<%
Dim RSresults
Dim RSresults_numRows
Set RSresults = Server.CreateObject("ADODB
RSresults.ActiveConnection
RSresults.Source = "SELECT * FROM qrylettings WHERE propID = " + Replace(RSresults__MMColPa
RSresults.CursorType = 0
RSresults.CursorLocation = 2
RSresults.LockType = 1
RSresults.Open()
RSresults_numRows = 0
%>
<!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>Property Sales</title>
<link href="maltings.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<h3><%=(RSresults.Fields.I
<div id="propimg">
<% if request.querystring("img")
<p><img src="prop-images/<%=(RSres
<% else %>
<p><img src="prop-images/<%=(RSres
<% end if %>
</div>
<div id="propdetails">
<p><strong>Area: </strong><%=(RSresults.Fie
<p><strong>Property Type: </strong><%=(RSresults.Fie
<p><strong>Price:</strong>
<% if RSresults.Fields.Item("ref
<p><strong>Property Reference: </strong>Property <%=(RSresults.Fields.Item(
<% end if %>
<% if RSresults.Fields.Item("ima
<% else %>
<% if request.querystring("img")
<p><strong>Images:</strong
<% else %>
<p><strong>Images:</strong
<% end if %>
<% end if %>
<% if request.querystring("img")
<p><a href="mailto:info@mrc-prop
<% else %>
<p><a href="mailto:info@mrc-prop
<% end if %>
</div>
<p>
<% Response.Write Replace(RSresults.Fields.I
</p>
<% if request.querystring("img")
<p><a href="javascript:history.b
<% else %>
<p><a href="javascript:history.g
<% end if %>
</div>
</body>
</html>
<%
RSresults.Close()
Set RSresults = Nothing
%>
woooah.. First time looking at a classic asp page - geez its much different than asp.net he he. I can't even load this in my IDE so I won't be able to help out on that end.
Let me say that I don't believe your javascript is going to work. Reason is you are dynamically generating your id's on your asp page (d=<%=RS("propID")%), which doesn't work the same on the clientside. One think you could try is passing the propID that is clicked to javascript as a parameter.
$('detail').click(function (propID) {
But this won't work..
$.post('lettings-detail.as p?id=<%=RS ("propID") %>',
$('detail<%=RS("propID")%> ').innerHT ML = detailslsInfo;
Let me say that I don't believe your javascript is going to work. Reason is you are dynamically generating your id's on your asp page (d=<%=RS("propID")%), which doesn't work the same on the clientside. One think you could try is passing the propID that is clicked to javascript as a parameter.
$('detail').click(function
But this won't work..
$.post('lettings-detail.as
$('detail<%=RS("propID")%>
Their library is easy to use, has great documentation, and some good examples. Here is an example of how you could apply that effect using YUI. The $('details-button).onclick
Open in new window