Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript var and VBSript dim (Urgent)

Posted on 2000-05-12
7
Medium Priority
?
291 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
Independent Software Vendors: 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

610 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