View Full Version : pop-up window
pinkcat_02
03-05-2003, 09:05 PM
Hi again
I am making an ASP page which gets all the data of items from Access DB. What I want to add now is:
when a user clicks on the pic of an item a new small window open with a bigger picture of the item plus it's description.
The thing is I want this small windows content generated dynamically as well that I don't wanna make a new window for each new item but instead it will be created by getting the content from the database.
Is this possible? Any ideas?
Morgoth
03-05-2003, 09:21 PM
I think a good idea is to do it this way, you can always make mods of it.
If (QueryString ID = nothing) then
redirect = "sorry picture not there"
Else
Open up DB connection
SQL = Select * from picture_info_table where ID = QueryString
Set RecordSet
<image = RS(picturelocation)>
<text = RS(picturedescription)>
Close db connection
End If
There you go, works great, now all you have to do is turn this simple sudo code into ASP.
You can make a new file to add this too, and have the popup window using VbScript (if possible) or Javascript, and have it make sure when the link to this page is added, the ID is also sent (.asp?id=#).
Understand? Doesn't seem difficult does it? Did you want all the code in the same page?
pinkcat_02
03-05-2003, 09:38 PM
I don't think u really understood what I am trying to say
I am looking for something that can be done with javascript and echo if i were using PHP. the pop up window will be exactly the same with the one in the parent page, but then there will be more than 1 item in each page and there will be 1 pop-up window for each item.
There are some examples of it done in coldfusion too but I have no idea how to do it in ASP or even no clue if i can do it.
Something like :
head:
<script language="JavaScript" type="text/JavaScript">
function newWindow (){
newWindow = window.open('<?php echo $row_viewall['pictures']; ?>','LargePicture', 'width=400, height=400,
scrollbars=no,resizable=yes,toolbar=no')
newWindow.document.write("<html><head><title>Large View<\/title><\/head><body
bgcolor=black><div align =center><p><?php echo $row_viewall['pictures'];?></p></div><\/body><\/html>")
newWindow.document.close()}
</script>
Body:
<a
href="javascript:newWindow()"><img src="<?php echo $row_viewall['thumbnail'];?>" alt="<?php echo $row_viewall['item_name']; ?>" border="0"></a></font>
</div></td>
I think Morgoth is not the only one that doesn't quite gets what you try to pull here. (I haven't got a clear picture of it).
Do you have an URL that shows this kind of functionality ?
I sounds to me like something you should solve by using a frame instead of a new window (cause you'll want the popup to apear in a part of the screen so that the other thumbnails stay visible + that way you wouldn't have to worry about using the same window for the second image that is selected)
pinkcat_02
03-06-2003, 09:19 PM
An example to what i am trying can be seen at:
http://www.newegg.com/app/viewproduct.asp?description=11-154-018&DEPA=1
there when you click on See it on the description part it opens a window with the picture of the item.
the link i am trying to do will be something like :
<a href="card.asp?id=<%=Card("id")%>" ONCLICK="window.name='A'; window.open('card.asp?id=<%=Card("id")%>','new', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes, resizable=no,copyhistory=no,width=600,height=600'); return false;" style="text-decoration: none">Önizleme</a>
pinkcat_02
03-07-2003, 12:50 AM
i have tried using :
<%
Dim oConn
Dim oRS
Dim sSQL
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\anticus\db\deneme3.mdb"))
sSQL = "SELECT Book_Picture from Book_Details "
Set oRS = oConn.Execute(sSQL)
do while oRS.EOF
%>
<%
Response.Write ("<a href="book.asp?id=<%=oRS("Book_ISPN")%>" ONCLICK="window.name='Details'; window.open('book.asp?id=<%=oRS("Book_ISPN")%>','new', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes, resizable=no,copyhistory=no,width=600,height=600'); return false;" style="text-decoration: none">Önizleme</a> <img src=""book/" & <%=oRS("Book_Picture")%>& """>")
%>
<%oRS.MoveNext
Loop
%>
<%
oConn.Close
Set oRS = Nothing
Set oConn = Nothing
%>
but it keeps giving me error which is:
Microsoft VBScript compilation error '800a03ee'
Expected ')'
/anticus/essek/book.asp, line 23
Response.Write ("<a href="book.asp?id=<%=oRS("Book_ISPN")
--------------------------^
Any idea what causes this problem?
pinkcat_02
when you use response.write, then you can only use single quotes (= ' ) in the html-yhat you're writing. Everything betwee double qupotes is written like straight html to the browser. So if you
For instance
response.write("blablable") will show up in a browser as blablable
if you have something like your
Response.Write ("<a href="book.asp?id=<%=oRS("Book_ISPN")%>"
then the parser will send this to the browser:
<a href=
(since you have " on both sides.) If you want to output html , you can only use singke quotes in the actual html code.
like this
Response.Write ("<a href='book.asp?id=" & oRS("Book_ISPN") & "'
If you want to switch from straigt html to variabbles and recordset values etc, you need to concatinate
That is: end the html by inserting a " then use a & to add variables to the string again an & ta add another html piece (which needs to begin with a " and end with a " etc. At the end, you need a )
You can't insert codesnippets like you did in a response.write.
<%=oRS("Book_ISPN")%>" should be "html" & oRS("Book_ISPN") & "html" .
When you want to insert a value like you did, the second html needs to start like this "' the rest of the html"
In short. You need to rewrite that whole string.
The erromessage you get usually points to a " where you hold have used a '.
pinkcat_02
03-07-2003, 02:25 PM
thanx raf,
I understod what u meant and to give it a try from the beginning I tired this... now it should show me the pictures but still it doesn't and it doesn't give any errors as well. What's wrong with this one... I tired to write it the way u had described me.
Response.Write (" <img src='book/" & oRS("Book_Picture") & "' >")
each image needs a width and height ...
so you need to set them also in the image tag. Like this
<img src="http://www.codingforums.com/images/icons/icon4.gif" border="0" width="15" height="15">
pinkcat_02
03-08-2003, 09:38 PM
To do the pop-up window I have written the code above but it gives me an error of:
ADODB.Recordset error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
I couldn't see where there the problem is do u have any idea?
my code is :
<%@ LANGUAGE=VBScript %>
<%
Response.Expires = 0
%>
<html>
<head>
<!--#include file="adovbs.inc" -->
<script language="javascript">
<!--//
function openwin(url,winheight,winwidth)
{
//Default sizes for window
if (winwidth==null) winwidth='600';
if (winheight==null) winheight='600';
popupwin = window.open(url, 'popupwin', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width='+winwidth+',h eight='+winheight);
popupwin.resizeTo(winwidth, winheight);
}
//-->
</script>
</head>
<body>
<%
Dim oConn
Dim oRS
Dim sSQL
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\anticus\db\deneme3.mdb"))
Set picsset = Server.CreateObject("ADODB.Recordset")
sqlselect = "SELECT Book_ISPN, Tittle, Description " &_
"FROM Book_Details " &_
"ORDER BY Book_ISPN"
picsset.Open sqlselect, adOpenStatic, adLockReadOnly, adCmdText
while not picsset.EOF
%>
<tr>
<td align="left" valign="top" width="165">
<a href="javascript:openwin('detail.asp?itemid=<%=picsset("Book_ISPN")%>, 200, 590)">
<img src="getthumb.asp?imgid=<%=picsset("Book_ISPN")%> alt="Picture"></a>
</td>
<td align="left" valign="top">
<font face="Arial" size="2">
<strong>Title:</strong><br>
<%=picsset("Title")%><br>
<strong>Description:</strong><br>
<%=picsset("Description")%></font>
</td>
</tr>
<tr>
<td colspan="3"><hr></td>
</tr>
<%
picsset.MoveNext
wend
%>
</body>
</html>
On what line is the error ?
pinkcat_02
03-09-2003, 06:08 PM
picsset.Open sqlselect, adOpenStatic, adLockReadOnly, adCmdText
it't this line which gives the error.
Thanks
the debugger points to that line, but the error will probably be in the sql statement (which is called here).
try writing the sql in stead of executing it
like response.write sqlselect.
at first looks, i don't se anything wrong with it. Althougd the way you link the line &_ looks strange to me. I alway go
line1 _
& line2 _
& line3
But you'll imedeately see what's wreong when you write the sql statement to the page (instead of running it)
pinkcat_02
03-10-2003, 11:36 PM
ok i have changed the sql like:
sqlselect = "SELECT ID, Tittle, Description from Book_Details ORDER BY ID"
and deleted the
picsset.Open sqlselect, adOpenStatic, adLockReadOnly, adCmdText
bit and added
reponse.write sqlselect and now i got the error:
SELECT ID, Tittle, Description from Book_Details ORDER BY ID
ADODB.Recordset error '800a0e78'
Operation is not allowed when the object is closed.
/anticus/essek/book.asp, line 47
then i tried putting those 2 lines together but then it gave the previous error so i have no clue where I have done wrong.
picsset.Open adOpenStatic, adLockReadOnly, adCmdText
response.write sqlselect
whammy
03-11-2003, 01:44 AM
Whoa, hold on.
First of all, raf is wrong about having to use single quotes when writing HTML, for instance:
Response.Write ("<a href="book.asp?id=<%=oRS("Book_ISPN")%>")
Is just fine - but instead you'd want to do this so you DO write double quotes, you just need to comment them out with another:
Response.Write ("<a href=""book.asp?id=""" & oRS("Book_ISPN") & """)
whammy
03-11-2003, 01:48 AM
As far as writing out your select statement to the page for debugging, try this:
sqlselect = "SELECT ID, Tittle, Description from Book_Details ORDER BY ID"
Response.Write(sqlselect) : Response.End
Hope this helps. :)
whammy
03-11-2003, 01:55 AM
P.S. It seems like you're getting way ahead of yourself with ASP, you should tackle one problem at a time!
I would get yourself a good ASP book like "Beginning ASP 3.0" by Wrox.com to start out with.
ASP/VBScript is not the best language to be programming in (since it allows for sloppy coding, unlike a lot of other languages), but if you have to use ASP, you really need some references and basic tutorials to get your "mindset" on VBScript, anyway.
It's a must - believe me, I have to FIX code all day that was done by people with 3-7 + years of programming experience, supposedly... and at times it's just terrible. ;)
If you already have programming knowledge in other languages, then ASP is easy to learn, but the features it DOES offer are often overlooked.
I know a guy that is a C++ programmer who uses 8 or more lines to create a simple date format (YYYYMMDD) that can be done like:
thisDate = Year(Now()) & Right("00" & Month(Now()),2) & Right("00" & Day(Now()),2)
:rolleyes:
whammy,
please read my comments on quotes before confusing other readers. The maybe aren't sophisticated and absolutely literally corrdct, but it are simple guidelines that produce easy readable and debuggable code.
To get this fire starting :), your two alternatives are bad formed coding ;) and i'm sure you never used coded-snippets like that
pinkcat_02,
about the errors you get:
if you remove the
picsset.Open sqlselect, adOpenStatic, adLockReadOnly, adCmdText
then you can't read value from the recordset are navigate through it (since there isn't one opened.
use whammy's tip to prevent the rest of the script from being parsed. (whammy still rules)
you dodn't need to delet ecode, just make a comment of it by placing a quote (') in front of the lines that don't have to be parsed.
dominicall
03-11-2003, 11:09 AM
I definitely agree with whammy - the Wrox 'Beginning ASP3' book is a must - I've been programming ASP now for about 4 years and I still keep it within reach as a reference - just in case.
whammy is also right about ASP/VBscript allowing sloppy coding - although there are a few basic disciplines that you should always follow that can help...
ALWAYS put the <%Option Explicit%> line in your page immediate after the <%@LANGUAGE=VBSCRIPT%> line. This will force you to declare variables and make life much easier when doing debugging - most problems stem from undeclared variables.
The it's simply a case of using Response.Write, Respond.End - iterating through your code until you find the error.
Another good discipline is to write and test all the recordset creation and closure code for the page before you write anything else. Just create the recordsets and then close them. That way, you know that any subsequent errors are not caused by creating the recordsets...
dominicall :D
whammy
03-11-2003, 01:25 PM
This is badly formed coding?!?:
Response.Write ("<a href=""book.asp?id=""" & oRS("Book_ISPN") & """)
Actually I use stuff like that all of the time. It ends up being much more modular and understandable with regards to the big picture (say for instance, if it's within a subroutine that is pretty much pure ASP code) rather than doing...
<a href="book.asp?id=<% = oRS("Book_ISPN") %>">Link</a>
Although I use both ways depending upon the situation. The latter is actually processed faster, in the newer versions of ASP (surprise, surprise), but the difference is probably in nanoseconds. :)
However, take this for instance:
<%
Function Indent(iInput)
If CInt(iInput) <> iInput Then Exit Function
Indent = Space(iInput*3)
End Function
Sub WriteNumericDropDown(sName,sValue,sStart,sEnd,sStep,iIndent)
Dim iCount
Response.Write(Indent(iIndent) & "<select name=""" & sName & """>" & vbCrLf)
For iCount = sStart TO sEnd Step sStep
Response.Write(Indent(iIndent + 1) & "<option value=""" & iCount & """")
Response.Write(IsSelected(CStr(iCount),sValue))
Response.Write(">" & iCount & "</option>" & vbCrLf)
Next
Response.Write(Indent(iIndent) & "</select>" & vbCrLf)
End Sub
%>
Ok, now that might take a few more nanoseconds to process, but with that sub I can write ANY numeric dropdown and stick it in HTML like this, for instance:
<% Call WriteNumericDropdown("EndDay",EndDay,1,31,1,5) %>
<% Call WriteNumericDropdown("EndYear",EndYear,Year(Now()) - 10,Year(Now()) + 10,1,5) %>
Which in the long run saves ME a lot of work, especially in a page that has a lot of numeric dropdowns or something. That's more important to me since I have a lot of deadlines to meet. Not to mention it's easily reusable (not as easy as classes in .NET, but what can ya do? ;)).
P.S. The Indent() function is just to make the source code look nice.
I don't know about you, but most of the HTML source code I see that's generated by ASP looks atrocious (and I wouldn't want anyone to look at my page source and go "Wow what the (*&!@)!".
Yeah well, you know i'm right ;) (i presume that, for the both of us, this is not about being right but about convincing and helping people).
I was mainly pointing out to pinkcat_02 where her code-error was.
And as always, being pedagogically right is not being absolutely right.
i stick with two easy principles for stuffing values in html:
- use response.write and include straight html in double quotes and concatinate with variables to include their value. The double quotes you normally use in the html are then replaced by single quotes.
example:response.write("<a href='adminmain.asp' title='" & rsTest.Fields("title") & "'>Mainpage</a>")
- write the html and use code snippets to include values from variables.
example: <a href="adminmain.asp" title="<%=rsTest.Fields("title")%> ">Mainpage</a>
A code snippet inside a response.write --> not done
Your second alternative --> never read or heard about that (so i learned something :)) + don't see the advantage of that (whats gained ?), since it can easialy be rewritten by concatinating the html and the variables (so why learn yet another technique when there are so much other languages you need to learn and maintain).
pinkcat_02
03-12-2003, 02:17 AM
hiya I have sorted out my problem it wasn't my sql code though it was just a silly mistake that I forgot to add oConn in my
picsset.Open sqlselect, adOpenStatic, adLockReadOnly, adCmdText
now it is working... i have also managed to retrieve a picture from database by storing the picture name in the database and using img src but then I tried to achieve the same task by stroing the image in the database.(using OLE object) but I failed... I dunno what is wrong with my code for me it just seems perfect. I got the book you have advised by the way ... thanks :)
My code is the one below can u see any problems that I couldn't?It just displays a blank image
<%
Dim SQL
Dim m_sSourceID
Dim oConn
Dim oRs
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db\d3.mdb"))
Response.Expires = 0
Response.Buffer = TRUE
Response.ContentType = "image/jpeg"
Set oConn = Server.CreateObject("ADODB.Connection")
Set oRs = Server.CreateObject("ADODB.Recordset")
m_sSourceID = Request("ID")
If (m_sSourceID <> "") Then
SQL = "SELECT ID, Book_Picture FROM Book_Details"
SQL = SQL & " WHERE ID = " & m_sSourceID
oRs.Open SQL, oConn
if NOT (oRs.EOF AND oRs.BOF) then
if oRs("Thumb").ActualSize > 0 then
Response.BinaryWrite oRs("Thumb").GetChunk(oRs ("Thumb").ActualSize)
end if
end if
oRs.Close
Set oRs = nothing
end if
Set oConn = nothing
Response.End
%>
I'm realy not an expert on this, since i alway just store the filename in the database.
Three recommendations:
- in the future, start a new thread for a new problem. A lott of people that know the answer won't see you post now. But if you start a new post with a good, signifficant title ...
- you can loose one of the if-then-else controls.
- Like i say, i'm not an expert, but this oRs("Thumb") doen't look right to me. Can this variable be in the recordset ? You only have two variables and you don't use an alias, so you should refere to one of them (ID or Book_Picture). The rest of that lien soesn't look ricght to me either.
Check this out. Its a short (2 pages ?) and easie way to work with both pictures and filenames that are stored in a db
(edit url. didn't work)
http://www.4guysfromrolla.com/webtech/060100-1.shtml
think this should give you what you're looking for.
If you need a sollution quickly, it's always a good idea to use a search angine and find out wat this or the othher forums has toi offer.
(my favorite searchengine is home.37.com which always turns up with some very useful sites.)
Roy Sinclair
03-12-2003, 03:44 PM
Originally posted by raf
Yeah well, you know i'm right ;) (i presume that, for the both of us, this is not about being right but about convincing and helping people).
I was mainly pointing out to pinkcat_02 where her code-error was.
And as always, being pedagogically right is not being absolutely right.
i stick with two easy principles for stuffing values in html:
- use response.write and include straight html in double quotes and concatinate with variables to include their value. The double quotes you normally use in the html are then replaced by single quotes.
example:response.write("<a href='adminmain.asp' title='" & rsTest.Fields("title") & "'>Mainpage</a>")
- write the html and use code snippets to include values from variables.
example: <a href="adminmain.asp" title="<%=rsTest.Fields("title")%> ">Mainpage</a>
A code snippet inside a response.write --> not done
Your second alternative --> never read or heard about that (so i learned something :)) + don't see the advantage of that (whats gained ?), since it can easialy be rewritten by concatinating the html and the variables (so why learn yet another technique when there are so much other languages you need to learn and maintain).
The problem with your approach is that standards have gone in the direction that parameters in HTML (actually xHMTL) should be double-quoted always and only. Of course it's not a problem with the current browsers but there's a mild chance that someone in the future will make a browser which actually demands proper code and your pages will have to be "fixed" then.
It would help if developers had such a browser today so they could test their pages with it first.
The principle I usually follow is to response write the html if it's in the midst of a lot of other code but to use the <%= %> form otherwise. What I try to reduce is the number of shifts between ASP and HTML since my understanding has been that it those shifts which cause more overhead. Of course with .NET that's no longer true but of course that's yet another animal anyway.
you've got a point about respecting (cleanest) html standards.
but i don't think my app's will live longer then browsers that except this kind a clean code. :)
by then i've been moved on (to other clients and languages)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.