Solved

Javascript var and VBSript dim (Urgent)

Posted on 2000-05-12
7
288 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

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!

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

690 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