?
Solved

Javascript var and VBSript dim (Urgent)

Posted on 2000-05-12
7
Medium Priority
?
290 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

765 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