asp code does not render for first record in looped recordset

H

haft

I have posted this question on a javascript forum as it contains
javascript code however it was believed to be an asp issue.

The following head section javascript code contains the function
showBigImage( isource,bigImage,header ) function call of discussion:

var currentImage;
function showBigImage( isource,bigImage,header ) {
var theImage = document.getElementById( 'largeimage' );
theImage.src = isource;
currentImage = bigImage;
document.getElementById( 'photoHeader' ).innerHTML=header;
document.getElementById( 'largeimage' ).alt=header;

The following rendered looped recordset code illustrates how the
"header" parameter of this showBigImage( isource,bigImage,header )
function call does not render ONLY FOR THE FIRST RECORD OF THE
RECORDSET as it is blank:

<a href= "javascript:;" > <td height=36 valign="middle"
class="small_img" onmouseover="showBigImage( 'imagescript.asp?
path=images/portable_stage.jpg&width=250','images/
portable_stage.jpg','' )"> <img src="imagescript.asp?path=images/
portable_stage.jpg&width=36" border="0" alt="" /> </td> </a>

<a href= "javascript:;" > <td height=36 valign="middle"
class="small_img" onmouseover="showBigImage( 'imagescript.asp?
path=images/seated_riserset.jpg&width=250','images/
seated_riserset.jpg','Portable stage configuration using 9 units of
the 3 ft x 8 ft platforms in 3 different heights' )"> <img
src="imagescript.asp?path=images/seated_riserset.jpg&width=36"
border="0" alt="" /> </td> </a>

<a href= "javascript:;" > <td height=36 valign="middle"
class="small_img" onmouseover="showBigImage( 'imagescript.asp?
path=images/Stageset.jpg&width=250','images/Stageset.jpg','Portable
stage configuration using 16 units of the 4 ft x 8 ft platforms' )">
<img src="imagescript.asp?path=images/Stageset.jpg&width=36"
border="0" alt="" /> </td> </a>

<a href= "javascript:;" > <td height=36 valign="middle"
class="small_img" onmouseover="showBigImage( 'imagescript.asp?
path=images/Runset.jpg&width=250','images/Runset.jpg','Portable stage
runset configuration' )"> <img src="imagescript.asp?path=images/
Runset.jpg&width=36" border="0" alt="" /> </td> </a>


Because of this problem, the caption text does not display for this
first image record once the thumbnail images are moused over. You can
view this page example at
http://www.canchair.com/new_web_product_detail.asp?ProductID=198&ProductFamily=1&ProductFamilySub=10
 
E

Evertjan.

wrote on 22 jul 2008 in microsoft.public.inetserver.asp.general:
I have posted this question on a javascript forum as it contains
javascript code however it was believed to be an asp issue.

There is no ASP code in the below.
The following head section javascript code contains the function
showBigImage( isource,bigImage,header ) function call of discussion:

var currentImage;
function showBigImage( isource,bigImage,header ) {
var theImage = document.getElementById( 'largeimage' );
theImage.src = isource;
currentImage = bigImage;
document.getElementById( 'photoHeader' ).innerHTML=header;
document.getElementById( 'largeimage' ).alt=header;

This is clientside code, so you are off topic.
 
B

Bob Barrows [MVP]

I have posted this question on a javascript forum as it contains
javascript code however it was believed to be an asp issue.

Given that there is no server-side code shown here, I'm not sure what
led whoever it was to believe that this was an ASP issue.

If it is an asp issue then we have no chance of debugging it without
seeing the server-side code contained in ...imagescript.asp
 
H

haft

Given that there is no server-side code shown here, I'm not sure what
led whoever it was to believe that this was an ASP issue.

If it is an asp issue then we have no chance of debugging it without
seeing the server-side code contained in ...imagescript.asp
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

You are absolutely right. I should've posted the asp code and here it
is:

<a href= "javascript:;" class="small_img" >
<td height=36 valign="middle"
class="small_img" onmouseover="showBigImage( 'imagescript.asp?path=<%=
images.Fields.Item( "url_img" ).Value %>&width=250','<%=
images.Fields.Item( "url_img" ).Value %>','<
%=(images.Fields.Item("alt_img").Value)%>' )"><img
src="imagescript.asp?path=<%= images.Fields.Item( "url_img" ).Value
%>&width=36" border="0" alt="" /> </td>
</a>
 
E

Evertjan.

wrote on 23 jul 2008 in microsoft.public.inetserver.asp.general:
You are absolutely right. I should've posted the asp code and here it
is:

<a href= "javascript:;" class="small_img" >
<td height=36 valign="middle"
class="small_img" onmouseover="showBigImage(
'imagescript.asp?path=<%images.Fields.Item( "url_img" ).Value
%>&width=250','<%images.Fields.Item( "url_img" ).Value %>','<
%=(images.Fields.Item("alt_img").Value)%>' )"><img
src="imagescript.asp?path=<%= images.Fields.Item( "url_img" ).Value
%>&width=36" border="0" alt="" /> </td>
</a>

If the ASP string is correct, even then this:

<%images.Fields.Item( "url_img" ).Value %>

will not do in ASP, or render to the html-string, anything,
so perhaps you want to try:

<% = images.Fields.Item( "url_img" ).Value %>

[etc.]

However,
since you do not show the relevant serverside database access code,
or even what database you use,
I cannot say.

And we do not know if imagescript.asp will process the querystring value
correctly

And if the resultstring of
<% = images.Fields.Item( "url_img" ).Value %>
is encoded to precvent it to have characters that break the querystring,
[like an apostrophe].

Even the html is wrong:
<td .... /></td>
[why the /> ?]
and
<a ...><td .... /></td>...</a>
is wrong,
and
<a href= "javascript:;" class="small_img" >
is questionable,
but that all is off topic on this NG.
 
B

Bob Barrows [MVP]

You are absolutely right. I should've posted the asp code and here it
is:

<a href= "javascript:;" class="small_img" >
<td height=36 valign="middle"
class="small_img" onmouseover="showBigImage( 'imagescript.asp?path=<%=
images.Fields.Item( "url_img" ).Value %>&width=250','<%=
images.Fields.Item( "url_img" ).Value %>','<
%=(images.Fields.Item("alt_img").Value)%>' )"><img
src="imagescript.asp?path=<%= images.Fields.Item( "url_img" ).Value
%>&width=36" border="0" alt="" /> </td>
</a>

Err ... that is not the code contained in imagescript.asp is it? No mention
of a recordset, for one thing ...
 
H

haft

i really appreciate the responses.


the imagescript page is the page that resizes the images but i have no
issues with the images but rather the alt_img database field not
rendering properly for the initial recordset value.

and database type is Access.


imagescript.asp code:

<%


Response.Expires = 0
' create instance of AspJpeg
Set Jpeg = Server.CreateObject("Persits.Jpeg")

If Request.QueryString("width")=36 Then
Jpeg.New 36, 36, &HFFFFFF
Else
Jpeg.New 250, 250, &HFFFFFF
End If

' Open source file
Jpeg.Open Server.MapPath(Request.QueryString("path"))

'Jpeg.Width = Request("Width")

L = Request("Width")

'Jpeg.Height = Jpeg.OriginalHeight * Jpeg.Width / Jpeg.OriginalWidth

If jpeg.OriginalWidth > jpeg.OriginalHeight Then
jpeg.Width = L
jpeg.Height = jpeg.OriginalHeight * L / jpeg.OriginalWidth
Else
jpeg.Height = L
jpeg.Width = jpeg.OriginalWidth * L / jpeg.OriginalHeight
End If

' Perform resizing and
' send resultant image to client browser
Jpeg.SendBinary

%>
 
H

haft

This is the code to narrow in on:

onmouseover="showBigImage( 'imagescript.asp?path=<%=
images.Fields.Item( "url_img" ).Value %>&width=250','<%=
images.Fields.Item( "url_img" ).Value %>','<
%=(images.Fields.Item("alt_img").Value)%>' )">

This '<%=(images.Fields.Item("alt_img").Value)%>' portion of the code
is what is not rendering for the initial image of the recordset
 
B

Bob Barrows [MVP]

i really appreciate the responses.


the imagescript page is the page that resizes the images but i have no
issues with the images but rather the alt_img database field not
rendering properly for the initial recordset value.

So I guess I still don't understand the suspicion that this is an
ASP/server-side code problem.
and database type is Access.


imagescript.asp code:
<snip>
Still no mention of a recordset ... ?
I don't know how we can help.
 
B

Bob Barrows [MVP]

This is the code to narrow in on:

onmouseover="showBigImage( 'imagescript.asp?path=<%=
images.Fields.Item( "url_img" ).Value %>&width=250','<%=
images.Fields.Item( "url_img" ).Value %>','<
%=(images.Fields.Item("alt_img").Value)%>' )">

This '<%=(images.Fields.Item("alt_img").Value)%>' portion of the code
is what is not rendering for the initial image of the recordset

No it isn't. There is no mention of a recordset here, unless images is a
recordset object. If so, we need to see the code used to open the
recordset (and its connection) as well as a description of the database
table (field datatypes and names), along with the code used to navigate
to the record whose alt_img field you wish to display. Try to slice out
as much html as possible so we can focus on the server-side ADO code.
 
D

Daniel Crichton

This is the code to narrow in on:
onmouseover="showBigImage( 'imagescript.asp?path=<%=
images.Fields.Item( "url_img" ).Value %>&width=250','<%=
images.Fields.Item( "url_img" ).Value %>','<
%=(images.Fields.Item("alt_img").Value)%>' )">
This '<%=(images.Fields.Item("alt_img").Value)%>' portion of the code
is what is not rendering for the initial image of the recordset


Silly question, but are you sure the value of alt_img for that row in the
database actually has a value?

And another thing to consider (which shouldn't affect this though) is that
you should ensure that there is no way to get an apostrophe into your
database, or if you do allow it that you ensure that you escape it (ie store
it as \') or else you risk breaking the javascript handling in the client
(or even worse potentially allowing cross-site scripting).
 
H

haft

CONNECTION SCRIPT PAGE CODE:

<%
' FileName="Connection_ado_conn_string.htm"
' Type="ADO"
' DesigntimeType="ADO"
' HTTP="true"
' Catalog=""
' Schema=""
Dim MM_Custom4_STRING
MM_Custom4_STRING = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" &
Server.MapPath("/access_db/Custom4.mdb")
%>

PAGE CODE OF DISCUSSION:

<!--#include file="Connections/Custom4.asp" -->
<%
Dim images
Dim images_numRows


Set images = Server.CreateObject("ADODB.Recordset")
images.ActiveConnection = MM_Custom4_STRING
images.Source = "SELECT url_img, alt_img, sort_img_prd, productfam,
productid_img, ColourAtt1, ColourAtt2, ColourAtt3, subfam, desc_fam,
title_fam FROM images WHERE productid_img = " +
Replace(images__MMColParam, "'", "''") + ""
If Request.QueryString("ProductFamily") <>"" Then
images.Source = images.Source & " OR
ProductFam="&Request.QueryString("ProductFamily")&""
End If
images.Source = images.Source & " AND ColourAtt1 IS NULL AND
ColourAtt2 IS NULL AND ColourAtt3 IS NULL ORDER BY sort_img_prd DESC"
'images.Source = "SELECT url_img, alt_img, sort_img_prd, productfam,
productid_img, ColourAtt1, ColourAtt2, ColourAtt3, sub, desc_fam,
title_fam FROM images WHERE productid_img = " +
Replace(images__MMColParam, "'", "''") + " OR (ProductFam=1) ORDER BY
sort_img_prd DESC"
images.CursorType = 0
images.CursorLocation = 2
images.LockType = 1
images.Open()

images_numRows = 0

%>


"images" is an access select query comprised of all the fields listed
in the above recordset select statement.
"alt_img" is a Memo Data Type (The General values listed are:
Required: No, Allow Zero Length: No, Indexed: Yes (Duplicates OK),
Unicode Compression: Yes, IME Mode: No Control, IME Sentence Mode:
None)

And no, there are no apostrophes in the alt_img values to be tripping
the javascript code and yes, the alt_img field does contain a value. I
have tested this page on 3 different products and the same occurs for
each as to verify that this is not a product-specific error.
 
B

Bob Barrows [MVP]

CONNECTION SCRIPT PAGE CODE:

<%
' FileName="Connection_ado_conn_string.htm"
' Type="ADO"
' DesigntimeType="ADO"
' HTTP="true"
' Catalog=""
' Schema=""
Dim MM_Custom4_STRING
MM_Custom4_STRING = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" &
Server.MapPath("/access_db/Custom4.mdb")
%>

OK, you should not be using the obsolete ODBC driver when there is a
native OLE DB Jet provider; the connection string should be

"Provider=Microsoft.Jet.OLEDB.4.0;" & _
data source = " & Server.MapPath("/access_db/Custom4.mdb")
Set images = Server.CreateObject("ADODB.Recordset")
images.ActiveConnection = MM_Custom4_STRING

Nothing to do with your problem, but this is poor coding practice. You
should use an explicit connection object to make sure connection pooling
can work properly:

dim cn:set cn = createobject)"adodb.connection")
cn.open MM_Custom4_STRING
images.Source = "SELECT url_img, alt_img, sort_img_prd, productfam,
productid_img, ColourAtt1, ColourAtt2, ColourAtt3, subfam, desc_fam,
title_fam FROM images WHERE productid_img = " +
Replace(images__MMColParam, "'", "''") + ""

Again, nothing to do with your problem, but the + signs should be &
symbols. A better practice would be to assign this string to a variable
which will make debugging easier:

dim sSQL
sSQL = "SELECT ... "
If Request.QueryString("ProductFamily") <>"" Then
images.Source = images.Source & " OR
ProductFam="&Request.QueryString("ProductFamily")&""
End If
images.Source = images.Source & " AND ColourAtt1 IS NULL AND
ColourAtt2 IS NULL AND ColourAtt3 IS NULL ORDER BY sort_img_prd DESC"
'images.Source = "SELECT url_img, alt_img, sort_img_prd, productfam,
productid_img, ColourAtt1, ColourAtt2, ColourAtt3, sub, desc_fam,
title_fam FROM images WHERE productid_img = " +
Replace(images__MMColParam, "'", "''") + " OR (ProductFam=1) ORDER BY
sort_img_prd DESC"

Same comment: don't assign this stuff directly to the Source property.
images.CursorType = 0
images.CursorLocation = 2
images.LockType = 1

Hmmm ... going to a lot of trouble to set default properties ...
images.Open()

Here is how it should look:
images.Open sSQL, cn,,,1
Actually, you could boil all the above down to:

dim sSQL
sSQL = "SELECT ... "
dim cn:set cn = createobject)"adodb.connection")
cn.open MM_Custom4_STRING
set images=cn.execute(sSQL,,1)

Make sure you close both the recordset and the connection when you are
finished using them.
images_numRows = 0

%>


"images" is an access select query
(excuse the nitpick)
Er, no. "images" is a recordset object opened using a select statement
run against a Jet database.
The select query is the string that hopefully you will change the code
to assign to sSQL.
comprised of all the fields listed
in the above recordset select statement.
"alt_img" is a Memo Data Type (The General values listed are:
Required: No,

So nulls are allowed ... You said you tested whether the first record
had a value in alt_img but failed to say how you tested this.
Allow Zero Length: No, Indexed: Yes (Duplicates OK),
Unicode Compression: Yes, IME Mode: No Control, IME Sentence Mode:
None)

I see no problems besides the poor coding practices I highlighted. Try
the changes i suggested, and if they don't help, I doubt this is an "asp
problem". It is likely to be a data problem with the data in the
database. One thing:
do you have the same problem if you change sort_img_prd DESC to
sort_img_prd ASC?
 
O

Old Pedant

Not sure why some posters thought this had anything to do with JS and nothing
to do with recordset.

I certainly don't know anything other than a recordset object that uses the
code pattern
[name].Field.Item('...fieldname...").Value

Now, it's also true that DumbWeaver is plunking in way too much code there.

The expression
<% = images.Fields.Item( "url_img" ).Value %>
is 100% equivalent to the easier-to-write, easier-to-read, and MEASURABLY
FASTER
<%=images("url_img")%>
And I do recommend that you switch to that.

***************

Having said all that.

I see no reason at all in any of your code that the first description
doesn't show up in the output. (And it's clearly nothing to do with
apostrophes...a VIEW-->>SOURCE of the HTML of your page shows that there is
NOTHING WHATSOEVER there.)

So I have to question your actual database. Are you 100% *SURE* that you
actually *HAVE* any text in the
alt_img
field for that given
url_img
value????

In other words, go into your Access database (using Access, not using ASP,
not using DumbWaster) and find the record where
url_img
is
images/portable_stage.jpg
Then, *IN THAT SAME RECORD*, find what the value of
alt_img
is. I am personally betting that the value is blank. And so you are
getting exactly what you should.

**********************

I do note that your code isn't *REALLY* doing what it *SHOULD* be doing.

You said to look at the UR
http://www.canchair.com/new_web_product_detail.asp?ProductID=198&ProductFamily=1&ProductFamilySub=10

I did. I also looked at
ProductID=111
and
ProductFamilySub=12
and tried various other combinations. And I still got the same images, no
matter what.

So given all that, maybe it's not surprising that the DB doesn't have a
value in one field when you think it should.

*************************************

By the not so insignifcant by...your HTML code is ILLEGAL. It is rendering
thus:

<a href= "javascript:;" class="small_img" >
<td height=36 valign="middle" class="small_img"
onmouseover="showBigImage(
'imagescript.asp?path=images/portable_stage.jpg&width=250','images/portable_stage.jpg',''
)"><img src="imagescript.asp?path=images/portable_stage.jpg&width=36"
border="0" alt="" > </td>
</a>
But it's illegal to have <A>...</A> tags *OUTSIDE* of the <TD>...</TD> tags.

As it turns out, MSIE is sloppy and allows this. Don't count on other
browser to do so.

Of course, the bigger question is a simple one: What's the point of the <A>
tag there, in the first place????? It is doing EXACTLY NOTHING. I would
string recommend removing the <A> and </A> tags.
 
B

Bob Barrows [MVP]

Old said:
Not sure why some posters thought this had anything to do with JS and
nothing
to do with recordset.

If you're asking why I missed it, the answer is simple: I do not expect to
see a recordset object named "images". Even if I had, I still had not seen
enough to decide where the problem was.
 
O

Old Pedant

Bob Barrows said:
If you're asking why I missed it, the answer is simple: I do not expect to
see a recordset object named "images".

I thought you weren't only one that missed that. I thought a couple of
other posters did.

But no matter. It's obvious you haven't had to work with the junk that DW
produces as much as I have. I recognized its patterns (even its BigImage
stuff) right off. I think, all in all, you should consider yourself very
fortunate. <grin/>

[I admit, I tend to go overboard, ragging on DreamWeaver, but sheesh!
They've been producing the same crappy code since 1998 or so. I'm sure
nobody is doing any active work on improving it, today, but you'd think that
SOMEBODY would have changed SOME of their idiocies back in 2000 through 2002
or so.]




Even if I had, I still had not seen
 
D

Dooza

Old said:
[I admit, I tend to go overboard, ragging on DreamWeaver, but sheesh!
They've been producing the same crappy code since 1998 or so. I'm sure
nobody is doing any active work on improving it, today, but you'd think that
SOMEBODY would have changed SOME of their idiocies back in 2000 through 2002
or so.]

Dreamweaver CS4 is in public beta, all they did was break the UI and
improve the CSS abilities. The server side code hasn't changed since DW8
where they introduced paramatised commands to help prevent SQL injection.

Dreamweaver users have been screaming out for improved server side code
support for many years. Due to the poor support of server side code, and
regular browsing of this newsgroup, I have improved my asp/vbscript
coding abilities, but still use Dreamweaver to "design" my web applications.

Steve
 
O

Old Pedant

Dooza said:
Dreamweaver users have been screaming out for improved server side code
support for many years. Due to the poor support of server side code, and
regular browsing of this newsgroup, I have improved my asp/vbscript
coding abilities, but still use Dreamweaver to "design" my web applications.

A smart person, you are. The dozen or so people who I've taken "in hand" do
pretty much the same thing: Do the HTML design with DW but then do all the
ASP coding (or at least much of it) by hand.

If nothing else, the amount of "kruft" that you get rid of that way makes
your pages run twice as fast.

[I don't do much HTML "design", and what I do is done with notepad or VS
2003, even when coding in ASP. I'm lucky in that I get to be the "backend"
to designers' front-ends.]
 
D

Dooza

Old said:
A smart person, you are. The dozen or so people who I've taken "in hand" do
pretty much the same thing: Do the HTML design with DW but then do all the
ASP coding (or at least much of it) by hand.

I recently found out that Stored Procedures can output more than 1
recordset, and that you can easily step to the next one in ASP/VBScript.
This is something Dreamweaver will never do, yet it can save you
making several trips to the database. Since I do everything I can with
Stored Procedures to keep my database as secure as possible, this is a
great trick to use.
If nothing else, the amount of "kruft" that you get rid of that way makes
your pages run twice as fast.

[I don't do much HTML "design", and what I do is done with notepad or VS
2003, even when coding in ASP. I'm lucky in that I get to be the "backend"
to designers' front-ends.]

I have always been a visual designer. One of my early jobs in tech
support was for HoTMetaL Pro. The only way to support a package like
that was to learn what it was trying to do. I soon found it was bloody
awful at making good code! So I bought a book, Web Master in a Nutshell,
and started to dabble. When I found Dreamweaver 2 it appeared to make
better code, and let me be more creative whilst still letting me take
control of the code... haven't looked back since then, and have made a
nice living from it so far, always learning on the way.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top