Can I pass a javascript value to .asp?

S

Sue Barth

Hi all,
I hope I'm in the right ng for this...

I made an .asp page that allows users to toggle thru a directory of photos.
The page accomplishes the following:
selects a directory of photos based on a drop down
uses the fso to obtain the # of photos in the directory
cycles thru the photos w forward and backward buttons that send the pic
# with a +1 or -1 value
retrieve's & displays the rs's photo description field from a db based
on its pic #

The thing that is awkward is that the page refreshes itself w ea request.
Is there any way to remain in .asp and not refresh?

OR

I found some javascript that is nice and will cycle thru the pics with the
forward & backward buttons, but I can't seem to make the javascript send the
value of the next or previous pic back to the .asp function that retrieves
the description field from the db. I definitely don't want to hardcode
these for each directory! And please forgive me, but I am not at all
proficient in js...

Has anyone ever done this before and if so, how can I retrieve that value?
Nothing I've done seems to work. The javascript picks up the values of the
..asp code on the initial load, but after that, I can't seem to make the
javascript functions requery the .asp function with the newly selected
picture #... The .asp values remain the same while the js values are
correctly changing...

Any advice would be greatly appreciated!
 
S

Sue Barth

Thanks for your reply, Aaron, but what a disappointment...

The article you referred me to seems to suggest that I might store the db
values in a hidden iframe. I'll give that a try. Maybe I should have the
..asp function loop thru the recordset and store the picture descriptions in
an array. Then perhaps it would be possible to have the javascript
functions retrieve that hidden info...Anyone have any thoughts on this? If
it would help to see what I'm trying to accomplish, the site is located at:
http://www.the-jam-factory.com/Forum/default_test.asp (bear in mind this is
my test page - it's currently set up with the javascript hooked to the
forward and backward buttons - and incorrectly passes the recordset info to
the picture caption textbox; I'm not using the dropdown on this page.)

What do other people do for photo albums that have info stored in a
database? Do they always have to refresh the page to display a new picture?

Any comments, suggestions, or just plain musings welcome...
==================================================
 
D

dlbjr

Sue,

Using JavaScript on the Client side.

Start a Timer and a Count Variable.
After each increment you set on the timer,
Call an asp page with the counter Variable as a querystring parm to get data using XMLHTTP object.
Replace innerHTML of page items with data
increment Count variable for next call.

Search using JavaScript and XMLHTTP

HTH

dlbjr
Pleading sagacious indoctrination!
 
L

Larry Bud

Sue Barth said:
Hi all,
I hope I'm in the right ng for this...

I made an .asp page that allows users to toggle thru a directory of photos.
The page accomplishes the following:
selects a directory of photos based on a drop down
uses the fso to obtain the # of photos in the directory
cycles thru the photos w forward and backward buttons that send the pic
# with a +1 or -1 value
retrieve's & displays the rs's photo description field from a db based
on its pic #

The thing that is awkward is that the page refreshes itself w ea request.
Is there any way to remain in .asp and not refresh?

The only way JS can "talk" to ASP is by refreshing the page, because
JS is run on the client, and ASP is run on the server. I'm not sure
why you're mixing the two in the case of a photo album.

If I were doing it, I'd just use ASP. Granted, with JS, you could
preload the images and when the user clicks a Next or Previous button,
it would quickly flip to the next picture.
 
S

Sue Barth

Hi Larry,

Yes, that's why I ended up wanting to use js in that it is VERY quick with
no page reloading. After I got the .asp page working first, it was
disappointing to see it refresh with each request. I'm learning a bunch
here about client / server stuff!

I'm just toying now with sending an array of the pic descriptions from the
recordset to a js array on the page's initial load. I don't know if it will
work, but I thought I'd give it one last try. dlbjr's advice was a bit over
my head...

Any other insights from the group would be welcome!

~ Sue
 
A

Aaron [SQL Server MVP]

If you are happy with IE only:

<%
set conn = CreateObject("ADODB.Connection")
conn.open "<connection string>"
set rs = conn.execute("SELECT picURL, picDescription FROM pictures")
scr = "<script>" & vbCrLf & _
"var picURLs = new Array();" & VBCrLf & _
"var picDescs = new Array();" & VBCrLf
ctr = 0
do while not rs.eof
scr = scr & "picURLs[" & ctr & "] = '" & rs("picURL") & _
"';" & vbCrLf & "picDescs[" & ctr & "] = '" & _
server.HTMLEncode(rs("picDescription")) & "';" & _
vbCrLf
ctr = ctr + 1
rs.movenext
loop
scr = scr & "var lastPos = " & (ctr-1) & ";" & vbCrLf & _
"</script>"

response.write scr
%>

<button onclick='moveBack();'>&lt;</button>
<span id=picdisplay></span>
<span id=picDescription></span>
<button onclick='moveForward();'>&gt;</button>

<script>
var curPos = 0;

function moveBack()
{
if (curPos > 0)
{
curPos = curPos - 1;
showImage(curPos);
}
}

function moveForward()
{
if (curPos < lastPos)
{
curPos = curPos + 1;
showImage(curPos);
}
}

function showImage(pos)
{
document.all("picDisplay").innerHTML = "<img src=" + picURLs[curPos]
+ ">";
document.all("picDescription").innerHTML = picDescs[curPos];
}

showImage(0);
</script>

Very rudimentary, feel free to fix the size of the divs, use tables, what
have you, but the generic functionality is there.
 
S

Sue Barth

Aaron, this is awesome - thanks so much! I will "play" tomorrow night! I
understand most of what you're doing here, and the thought actually went
thru my head to have .asp write out the js with an array of the values I
needed on the page's load, but I wasn't good enough in javascript to
accomplish it. Also, I haven't used HTMLEncode before, so I will read up on
that too - appreciate this a LOT... Too bad for Netscape, Opera, etc... tho
~ Sue

Aaron said:
If you are happy with IE only:

<%
set conn = CreateObject("ADODB.Connection")
conn.open "<connection string>"
set rs = conn.execute("SELECT picURL, picDescription FROM pictures")
scr = "<script>" & vbCrLf & _
"var picURLs = new Array();" & VBCrLf & _
"var picDescs = new Array();" & VBCrLf
ctr = 0
do while not rs.eof
scr = scr & "picURLs[" & ctr & "] = '" & rs("picURL") & _
"';" & vbCrLf & "picDescs[" & ctr & "] = '" & _
server.HTMLEncode(rs("picDescription")) & "';" & _
vbCrLf
ctr = ctr + 1
rs.movenext
loop
scr = scr & "var lastPos = " & (ctr-1) & ";" & vbCrLf & _
"</script>"

response.write scr
%>

<button onclick='moveBack();'>&lt;</button>
<span id=picdisplay></span>
<span id=picDescription></span>
<button onclick='moveForward();'>&gt;</button>

<script>
var curPos = 0;

function moveBack()
{
if (curPos > 0)
{
curPos = curPos - 1;
showImage(curPos);
}
}

function moveForward()
{
if (curPos < lastPos)
{
curPos = curPos + 1;
showImage(curPos);
}
}

function showImage(pos)
{
document.all("picDisplay").innerHTML = "<img src=" + picURLs[curPos]
+ ">";
document.all("picDescription").innerHTML = picDescs[curPos];
}

showImage(0);
</script>

Very rudimentary, feel free to fix the size of the divs, use tables, what
have you, but the generic functionality is there.

--
http://www.aspfaq.com/
(Reverse address to reply.)




Sue Barth said:
Hi Larry,

Yes, that's why I ended up wanting to use js in that it is VERY quick with
no page reloading. After I got the .asp page working first, it was
disappointing to see it refresh with each request. I'm learning a bunch
here about client / server stuff!

I'm just toying now with sending an array of the pic descriptions from the
recordset to a js array on the page's initial load. I don't know if it
will
work, but I thought I'd give it one last try. dlbjr's advice was a bit
over
my head...

Any other insights from the group would be welcome!
 
S

Sue Barth

Hi Aaron,
I made a few adjustments to suit my page and eventually got things working -
thankyou... I had trouble getting the pictures to display in the <span>
tag, - so I ended up using these 2 lines instead and, for whatever reason,
they ended up working:

eval('document.picDisplay.src = picFolders[curPos]');

<div align="center"><br><img SRC="<% response.write picFolder & "Pic01.jpg"
%>" NAME="picDisplay" border="3"></div>


I'm still having 2 little problems that I can't seem to solve on my own no
matter what I try...

First Issue:
I see the .asp code is correctly writing the array to the js - but the one
variable's value, lastPos, isn't being detected in a function I added...

I added moveFirst() and moveLast() - moveFirst works where moveLast
doesn't...

function moveFirst(){
curPos = 0;
showImage(curPos);
}

function moveLast(){
//I added the line below, but it the function doesn't work with it or
without it: - picNums is based on the fso routine:
//For Each objFile in objFolder.Files
// if right(objFile.name,4)=".jpg" and left(objFile.name,3)="Pic" then
// numPics=numPics+1
// else
// end if
//next

lastPos="<% response.write numPics %>"; //this line is the one that
seems to do nothing
showImage(lastPos);
}

Second Issue:
I used the onload event to display the first picture and its description,
but that's not working either. The picture displays, but I'm sure it's
because I put it in the img src of picDisplay. Seems this should work 'cuz
the button's onclick event fires it:
onLoad="moveFirst();"

So - if you have time and would be so kind as to take a look, the page is
at:
http://www.the-jam-factory.com/Forum/Default_Text.asp
and a text version of the code is at:
http://www.the-jam-factory.com/Forum/Code for Newsgroup Help.txt

Thanks so much,
~ Sue


Aaron said:
If you are happy with IE only:

<%
set conn = CreateObject("ADODB.Connection")
conn.open "<connection string>"
set rs = conn.execute("SELECT picURL, picDescription FROM pictures")
scr = "<script>" & vbCrLf & _
"var picURLs = new Array();" & VBCrLf & _
"var picDescs = new Array();" & VBCrLf
ctr = 0
do while not rs.eof
scr = scr & "picURLs[" & ctr & "] = '" & rs("picURL") & _
"';" & vbCrLf & "picDescs[" & ctr & "] = '" & _
server.HTMLEncode(rs("picDescription")) & "';" & _
vbCrLf
ctr = ctr + 1
rs.movenext
loop
scr = scr & "var lastPos = " & (ctr-1) & ";" & vbCrLf & _
"</script>"

response.write scr
%>

<button onclick='moveBack();'>&lt;</button>
<span id=picdisplay></span>
<span id=picDescription></span>
<button onclick='moveForward();'>&gt;</button>

<script>
var curPos = 0;

function moveBack()
{
if (curPos > 0)
{
curPos = curPos - 1;
showImage(curPos);
}
}

function moveForward()
{
if (curPos < lastPos)
{
curPos = curPos + 1;
showImage(curPos);
}
}

function showImage(pos)
{
document.all("picDisplay").innerHTML = "<img src=" + picURLs[curPos]
+ ">";
document.all("picDescription").innerHTML = picDescs[curPos];
}

showImage(0);
</script>

Very rudimentary, feel free to fix the size of the divs, use tables, what
have you, but the generic functionality is there.

--
http://www.aspfaq.com/
(Reverse address to reply.)




Sue Barth said:
Hi Larry,

Yes, that's why I ended up wanting to use js in that it is VERY quick with
no page reloading. After I got the .asp page working first, it was
disappointing to see it refresh with each request. I'm learning a bunch
here about client / server stuff!

I'm just toying now with sending an array of the pic descriptions from the
recordset to a js array on the page's initial load. I don't know if it
will
work, but I thought I'd give it one last try. dlbjr's advice was a bit
over
my head...

Any other insights from the group would be welcome!
 
S

Sue Barth

Aaron, just in case you see this post and want to help, I've resolved the
first issue from my last post (got the moveLast() function to work). All
that remains is firing the moveFirst or showImage function on the page
load... If you can figure that out for me, that would be awesome...

Thanks again - this is wonderful,
~ Sue

Aaron said:
If you are happy with IE only:

<%
set conn = CreateObject("ADODB.Connection")
conn.open "<connection string>"
set rs = conn.execute("SELECT picURL, picDescription FROM pictures")
scr = "<script>" & vbCrLf & _
"var picURLs = new Array();" & VBCrLf & _
"var picDescs = new Array();" & VBCrLf
ctr = 0
do while not rs.eof
scr = scr & "picURLs[" & ctr & "] = '" & rs("picURL") & _
"';" & vbCrLf & "picDescs[" & ctr & "] = '" & _
server.HTMLEncode(rs("picDescription")) & "';" & _
vbCrLf
ctr = ctr + 1
rs.movenext
loop
scr = scr & "var lastPos = " & (ctr-1) & ";" & vbCrLf & _
"</script>"

response.write scr
%>

<button onclick='moveBack();'>&lt;</button>
<span id=picdisplay></span>
<span id=picDescription></span>
<button onclick='moveForward();'>&gt;</button>

<script>
var curPos = 0;

function moveBack()
{
if (curPos > 0)
{
curPos = curPos - 1;
showImage(curPos);
}
}

function moveForward()
{
if (curPos < lastPos)
{
curPos = curPos + 1;
showImage(curPos);
}
}

function showImage(pos)
{
document.all("picDisplay").innerHTML = "<img src=" + picURLs[curPos]
+ ">";
document.all("picDescription").innerHTML = picDescs[curPos];
}

showImage(0);
</script>

Very rudimentary, feel free to fix the size of the divs, use tables, what
have you, but the generic functionality is there.

--
http://www.aspfaq.com/
(Reverse address to reply.)




Sue Barth said:
Hi Larry,

Yes, that's why I ended up wanting to use js in that it is VERY quick with
no page reloading. After I got the .asp page working first, it was
disappointing to see it refresh with each request. I'm learning a bunch
here about client / server stuff!

I'm just toying now with sending an array of the pic descriptions from the
recordset to a js array on the page's initial load. I don't know if it
will
work, but I thought I'd give it one last try. dlbjr's advice was a bit
over
my head...

Any other insights from the group would be welcome!
 
S

Sue Barth

ps - just fyi: I just tested the page in Netscape 7.1 and Opera 7.23 - both
worked well!

Aaron said:
If you are happy with IE only:

<%
set conn = CreateObject("ADODB.Connection")
conn.open "<connection string>"
set rs = conn.execute("SELECT picURL, picDescription FROM pictures")
scr = "<script>" & vbCrLf & _
"var picURLs = new Array();" & VBCrLf & _
"var picDescs = new Array();" & VBCrLf
ctr = 0
do while not rs.eof
scr = scr & "picURLs[" & ctr & "] = '" & rs("picURL") & _
"';" & vbCrLf & "picDescs[" & ctr & "] = '" & _
server.HTMLEncode(rs("picDescription")) & "';" & _
vbCrLf
ctr = ctr + 1
rs.movenext
loop
scr = scr & "var lastPos = " & (ctr-1) & ";" & vbCrLf & _
"</script>"

response.write scr
%>

<button onclick='moveBack();'>&lt;</button>
<span id=picdisplay></span>
<span id=picDescription></span>
<button onclick='moveForward();'>&gt;</button>

<script>
var curPos = 0;

function moveBack()
{
if (curPos > 0)
{
curPos = curPos - 1;
showImage(curPos);
}
}

function moveForward()
{
if (curPos < lastPos)
{
curPos = curPos + 1;
showImage(curPos);
}
}

function showImage(pos)
{
document.all("picDisplay").innerHTML = "<img src=" + picURLs[curPos]
+ ">";
document.all("picDescription").innerHTML = picDescs[curPos];
}

showImage(0);
</script>

Very rudimentary, feel free to fix the size of the divs, use tables, what
have you, but the generic functionality is there.

--
http://www.aspfaq.com/
(Reverse address to reply.)




Sue Barth said:
Hi Larry,

Yes, that's why I ended up wanting to use js in that it is VERY quick with
no page reloading. After I got the .asp page working first, it was
disappointing to see it refresh with each request. I'm learning a bunch
here about client / server stuff!

I'm just toying now with sending an array of the pic descriptions from the
recordset to a js array on the page's initial load. I don't know if it
will
work, but I thought I'd give it one last try. dlbjr's advice was a bit
over
my head...

Any other insights from the group would be welcome!
 
S

Sue Barth

Yes, I tried that line, but it gave an error if I left it where it was in
the code. Perhaps I should have put it somewhere else - and that's what I
was trying to accomplish on the onload event. Should it go somewhere else?

Thanks for your time; that's the only thing left! :)
~ Sue
 
A

Aaron [SQL Server MVP]

WHAT error? Can you show where this happens (the URL you provided earlier
gave a 404)?
 
A

Aaron [SQL Server MVP]

Well, you changed the code! I didn't use the src property of an image. If
you're going to do this, then you need to say:

document.images["picDisplay"].src

Instead of:

document.picDisplay.src

I'm setting the follow-up to the jscript newsgroup because your issue no
longer involves ASP.
 

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,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top