Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 31st, 2005, 01:25 PM
Registered User
 
Join Date: Oct 2005
Location: Melbourne, FL, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default capturing asp data in clientside javascript

I need to either open a database with javascript or pass an asp array to a javascript array, the following is what I've tried.
In the <head>:

var arrCollageImg = new Array;
arrCollageImg = <%=arrCollageData%>;

Then later in the <body> of the page I will do the following:

<script type="text/javascript">
  for(var i=0;i<arrCollageImg.length - 1; i++){
   document.write("<div>");
   document.write("<img src='images/collage/" + arrCollageImg[4][i] + "'")
   document.write("/<div>");
  }
</script>

Any help will be apprieciated.



Terry Migliorino
Reply With Quote
  #2 (permalink)  
Old October 31st, 2005, 01:42 PM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Terry,

How you populate your client-side array will depend on it's dimensions in the server side array.
So for an array in ASP / VBScript you could do something like...
Code:
var arrCollageImg = new Array();
<%
For i = 0 To UBound(arrCollageData)
    Response.Write "arrCollageImg[" & i & "] = """ & Replace(arrCollageData, """", "\""") & """;"
Next
%>
HTH,

Chris

Reply With Quote
  #3 (permalink)  
Old October 31st, 2005, 01:52 PM
Registered User
 
Join Date: Oct 2005
Location: Melbourne, FL, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Cris.

I'm still getting an error, but it may be in my asp code (which is vbscript).



Terry Migliorino
tmigliorino@usa.net
Reply With Quote
  #4 (permalink)  
Old November 1st, 2005, 04:26 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Terry,

Can you post your code and the error, please (including where the array is populated in ASP)?

Cheers,

Chris

Reply With Quote
  #5 (permalink)  
Old November 1st, 2005, 07:19 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

you can connect to a DB with JavaScript, but it is not recommended for security reasons.

also, if arrCollageImg has no elements it cant pick out a UBound.

Picco

www.crmpicco.co.uk
Reply With Quote
  #6 (permalink)  
Old November 1st, 2005, 03:57 PM
Registered User
 
Join Date: Oct 2005
Location: Melbourne, FL, USA.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is the vbscript that populates arrPageData.

<%
    dim oRS, arrPageData, intArrLen1, intArrLen2

    select case session("sesPageName")
        case "restorationPage"
            strSql = "qryAllRestorationData"
        case "retouchingPage"
            strSql = "qryAllRetouchingData"
        case "collagePage"
            strSql = "qryAllCollageData"
        case "galleryDigitalMenuPage"
            strSql = "qryAllDigitalGalleryData"
        case "galleryPhotoMenuPage"
            strSql = "qryAllPhotoGalleryData"
    end select

    Set oRS = Server.CreateObject("ADODB.Recordset")
    oRS.Open strSql, "dsnCJMGData", adOpenStatic, adLockOptimistic
    arrPageData = oRS.GetRows
    intArrLen = ubound(arrPageData,2)
    oRs.Close
    Set oRs = Nothing
%>

This is the page code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<%
    session("sesPageName") = "collagePage"
%>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta name=vs_defaultClientScript content="JavaScript">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="GENERATOR" content="Microsoft FrontPage 6.0" />
<meta name="ProgId" content="FrontPage.Editor.Document" />
<link rel="stylesheet" type="text/css" href="CJMGraphicsPublic.css" />


<title>CJM Graphics Collage Page</title>
<script language="javascript">
<!--
var arrCollageImg = new Array();
<%
--------------------------------------------------
----The error says syntex error at this point ----
--------------------------------------------------
For i = 0 To UBound(arrCollageData,0)
    For j = 0 to UBound(arrCollageData,1)
        Response.Write "arrCollageImg[" & i & "][" & j & "] = """ & Replace(arrCollageData, """", "\""") & """;"
    Next
Next
%>
//-->
</script>
</head>

<body>
<script type="text/javascript">
  for(var i=0;i<arrCollageImg.length - 1; i++){
   document.write("<div>");
   document.write("<img src='images/collage/" + arrCollageImg[4][i] + "'")
   document.write("/<div>");
  }
</script>

</body>

</html>

</html>


Terry Migliorino
tmigliorino@usa.net
Reply With Quote
  #7 (permalink)  
Old November 2nd, 2005, 05:29 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

i'm having a similar problem:

Code:
    var cabin = "<%=cabin_name%>";
    alert("cabin = " + cabin);
Why wont this work? I have set the value cabin name in the ASP??

Picco

www.crmpicco.co.uk
Reply With Quote
  #8 (permalink)  
Old November 2nd, 2005, 05:37 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Terry,

The second argument of UBound should be 1 for the first dimension, 2 for the second etc. not 0, 1, ...

HTH,

Chris

Reply With Quote
  #9 (permalink)  
Old November 2nd, 2005, 07:52 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Picco,

You code looks fine, there must be an error somewhere else in the page - the variable may have gone out of scope / be empty / etc.

Cheers,

Chris

Reply With Quote
  #10 (permalink)  
Old November 2nd, 2005, 09:10 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

the general structure is

ASP Page:

<%
asp code....

%>
<scrript src="inc.js>

<% cabin_name = "UUUU" %>

can i not get "cabin_name" inside the inc.js file?

www.crmpicco.co.uk
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Capturing MSHFlexGrid Data davekrunal46 VB How-To 2 November 30th, 2005 03:00 AM
capturing asp data in clientside javascript Terry Joseph Migliorino Javascript 1 October 31st, 2005 01:42 PM
Global Variables and ClientSide Javascript haricot Classic ASP Basics 3 September 7th, 2005 10:00 AM
Capturing Javascript form via Excel web query helentoomik Javascript 3 November 25th, 2004 12:19 PM



All times are GMT -4. The time now is 01:20 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.