Solved

Javascript var and VBSript dim (Urgent)

Posted on 2000-05-12
7
281 Views
Last Modified: 2008-03-17
Dear all,

The information are provided here:
1. I have retrive some records from a database, then store it in an array (Varaible of VBS)

2. In that page, I have a combo box control, and I assign the onclick to a javascript function

3. in that javascript function, I need to use the values that are stored in (1), i.e. in the database array , however, I need to know the indexselected to get the value from the array. How can I do this?

it is shown here:
javascript:
function name () {
 How can I get
 Array(document.form.select.value) here???
}

<form ... >
<select ... onclick = "name()">
...

Thanks!
0
Comment
Question by:edwardpoon
7 Comments
 
LVL 4

Expert Comment

by:ruperts
ID: 2805166
Gives you the selected value.

document.formname.selectname.options[document.formname.selectname.options.selectedIndex].text


0
 
LVL 19

Expert Comment

by:daveamour
ID: 2805184
Not quite

Try this

document.formname.selectname.options[document.formname.selectname.selectedIndex].value

Dave
0
 

Author Comment

by:edwardpoon
ID: 2805211
Sorry, what I mean the value that I would like to retrive is not that is stored in the control objects.
But I have stored them in an VBS array variable.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:edwardpoon
ID: 2805220
that is, say
I have :

Array(1) = "value1"
Array(2) = "value2"
Array(3) = "value3"

I want to get
Array(selectedindex)

(Note that the value stored in the array is not equal to the value of the control.value)

thx
0
 
LVL 4

Accepted Solution

by:
fruey earned 50 total points
ID: 2805602
You can't access ASP variables directly through Javascript without passing them somehow.

You might do this:

in ASP that generates the page

'Preceeding Asp code here
%>
<SCRIPT>
function whatever {

MyArray = newArray(<%=Array(1)%>,<%=Array(2)%>,<%=Array(3)%>)

}
<%
'following ASP code here

That way you can populate your Javascript array with the same values as the ASP array. However, if you're referencing to the Array index, then both Javascript and VBScript use 0 as the first reference so perhaps do this to keep the references the same:

%>
<SCRIPT>
function whatever {

MyArray = newArray(<%=Array(0),<%=Array(1)%>,<%=Array(2)%>,<%=Array(3)%>)

}
<%


Obviously if an array has a lot of elements you can put this all in a loop to save typing
(javascript)
MyArray = newArray(25)
<%
for x = 0 to 24
%>
MyArray[0] = <%=Array(x)%>
<%
next
'ASP code continues

Hope this is clear
0
 
LVL 4

Expert Comment

by:fruey
ID: 2805612
p.s.

If the array contains strings, then you'll have to put quotes around like this

MyArray = newArray(25)
<%
for x = 0 to 24
%>
MyArray[0] = "<%=Array(x)%>"
<%
next

The point is that ASP always executes before Javascript code, so I think you'd be best to pass the ASP array into the Javascript. Then the Javascript can calculate the stuff it needs to and either pass the stuff back to the ASP as hidden form elements with a submit, or just directly display what you need it to display.
0
 

Author Comment

by:edwardpoon
ID: 2805613
That's exactly what I want! Thx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now