Solved

Javascript var and VBSript dim (Urgent)

Posted on 2000-05-12
7
280 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

757 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

17 Experts available now in Live!

Get 1:1 Help Now