asp with javascript

J

josema

Hi to all

I have a asp page that have an array for instance:
<%
a(0)=0
a(1)=1
a(2)=2
a(3)=3
%>
I would like to show each element of the array with
alerts in javascript... Do you know what its the way to
make something like this...

Thanks in advance and happy new year.
josema
 
D

Dan Boylett

josema said:
Hi to all

I have a asp page that have an array for instance:
<%
a(0)=0
a(1)=1
a(2)=2
a(3)=3
%>
I would like to show each element of the array with
alerts in javascript... Do you know what its the way to
make something like this...

You need to write your server code into a locally held array - excuse my JS
if it's wrong in terms of syntax, but I tend to program in VB and I'm not
looking up the JS syntax :))

So :
<%
a(0)=0
a(1)=1
a(2)=2
a(3)=3
%>
<html>
<body>
<script language ="javascript">
var aLocal(3)

<%
iCounter = 0
for (iCounter=0;iCounter<a.length;iCounter++) {
Response.Write('aLocal(' + iCounter + ') = ' + a(iCounter) + vbnewline
// Whatever the Jscript equivlant is - \n ?
}
%>
for(a=0;a<aLocal.length;a++) {
alert(aLocal(a))
}
</script>
</body>
</html>
 
H

Harag

Alert is a CLIENT site command.

so you would either have the asp code write client code... or just
simply use Response.Write to write out the value.

asp:

for (var i=0; i<a.length; i++) {
Response.Write ('<br>a['+i+'] = ' + a);
}

client:

<script language="javascript">
<%
for (var i=0; i<a.length; i++) {
Response.Write ('alert ("a['+i+'] = ' + a+ '")');
}

%>
</script>

Last bit not tested as I have a seperate function called "DebugOut"
which basically does the ASP way with colors and only if on localhost.


HTH.

Al
 
J

Josema

Sorry Dan,but my before explication was not correctly

The question is that i have an array in asp with money...

this array allways have the same number of elements, but
the value of each element is dinamic
<%
array(0)=5$
array(1)=6$
%>

and in the browser i have one like this:

<select name=x onchange=.....>
<option value=first>money1</option>
<option value=second>money2</option>
</select>

and a textbox simple

My program must do this...
If a user selects the option money1, the textbox.value
must be 5$

If a user selects the option money2, the textbox.value
must be 6$

Its like i cant connect the javascript with the asp,
cause one execute in the server and the another in the
client...
 
H

Harag

OK relooking at the OP I'm confused, are your coding ASP in VBscript
or Jscript ???

in VBscript arrays are used with rounded brackets and Jscript uses sqr
brackets
eg
VBscript: myArray(5)
Jscript: myArray[5]

The code I wrote b4 was for ASP Jscript.

so for ASP VBscript you could do this:


' direct to Page:
DIM i
for i = 0 to ubound(a)
Response.Write "<br>a("& i &") ="' & a(i));
next



<!--As clientside alerts: -->
<script language="javascript">
<%
DIM i
for i = 0 to ubound(a)
Response.Write "alert (""a("& i &") =" & a(i) & """);" ;
next

%>
</script>


HTH.
Al


Alert is a CLIENT site command.

so you would either have the asp code write client code... or just
simply use Response.Write to write out the value.

asp:

for (var i=0; i<a.length; i++) {
Response.Write ('<br>a['+i+'] = ' + a);
}

client:

<script language="javascript">
<%
for (var i=0; i<a.length; i++) {
Response.Write ('alert ("a['+i+'] = ' + a+ '")');
}

%>
</script>

Last bit not tested as I have a seperate function called "DebugOut"
which basically does the ASP way with colors and only if on localhost.


HTH.

Al


Hi to all

I have a asp page that have an array for instance:
<%
a(0)=0
a(1)=1
a(2)=2
a(3)=3
%>
I would like to show each element of the array with
alerts in javascript... Do you know what its the way to
make something like this...

Thanks in advance and happy new year.
josema
 
J

josema

Its in vbscript, thanks Harag, i post a message... My
initial question was not 100% correct exposed...
Thanks
Josema
-----Original Message-----

OK relooking at the OP I'm confused, are your coding ASP in VBscript
or Jscript ???

in VBscript arrays are used with rounded brackets and Jscript uses sqr
brackets
eg
VBscript: myArray(5)
Jscript: myArray[5]

The code I wrote b4 was for ASP Jscript.

so for ASP VBscript you could do this:


' direct to Page:
DIM i
for i = 0 to ubound(a)
Response.Write "<br>a("& i &") ="' & a(i));
next



<!--As clientside alerts: -->
<script language="javascript">
<%
DIM i
for i = 0 to ubound(a)
Response.Write "alert (""a("& i &") =" & a(i) & """);" ;
next

%>
</script>


HTH.
Al


Alert is a CLIENT site command.

so you would either have the asp code write client code... or just
simply use Response.Write to write out the value.

asp:

for (var i=0; i<a.length; i++) {
Response.Write ('<br>a['+i+'] = ' + a);
}

client:

<script language="javascript">
<%
for (var i=0; i<a.length; i++) {
Response.Write ('alert ("a['+i+'] = ' + a + '")');
}

%>
</script>

Last bit not tested as I have a seperate function called "DebugOut"
which basically does the ASP way with colors and only if on localhost.


HTH.

Al


Hi to all

I have a asp page that have an array for instance:
<%
a(0)=0
a(1)=1
a(2)=2
a(3)=3
%>
I would like to show each element of the array with
alerts in javascript... Do you know what its the way to
make something like this...

Thanks in advance and happy new year.
josema


.
 
H

Harag

see the 3 changes in your code, not tested but heading in the right
direction

HTH

Al.
 
A

Alex G

<%
Response.Write("<script>")
for i = 0 to UBound(a())
Response.Write "alert(""" & a(i) & """);"
Next
Response.Write("</script>")
%>
 
R

Roland Hall

: ><script language="javascript">

Something to note:

In ASP you define the default language:

<%@ LANGUAGE=VBScript %>

If you want to include servers-side script blocks, in any language (VBS/JS),
you have to specify the language.

<script language="jscript" runat=server>

However, on the client-side, you specify it differently since language= has
been deprecated.

<script type="text/jscript">

--
Roland

This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.
-Technet Knowledge Base-
http://support.microsoft.com/default.aspx?scid=fh;EN-US;kbhowto&sd=TECH&ln=EN-US&FR=0
-Technet Script Center-
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/default.asp
-MSDN Library-
http://msdn.microsoft.com/library/default.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top