asp with javascript

Discussion in 'ASP General' started by josema, Jan 9, 2004.

  1. josema

    josema Guest

    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
    josema, Jan 9, 2004
    #1
    1. Advertising

  2. josema

    Dan Boylett Guest

    "josema" <> wrote in message
    news:0a0701c3d6a6$fdf5de90$...
    > 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>
    Dan Boylett, Jan 9, 2004
    #2
    1. Advertising

  3. josema

    Harag Guest

    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


    On Fri, 9 Jan 2004 03:52:01 -0800, "josema"
    <> wrote:

    >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
    Harag, Jan 9, 2004
    #3
  4. josema

    Josema Guest

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


    >-----Original Message-----
    >
    >"josema" <> wrote in

    message
    >news:0a0701c3d6a6$fdf5de90$...
    >> 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>
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >.
    >
    Josema, Jan 9, 2004
    #4
  5. josema

    Harag Guest

    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


    On Fri, 09 Jan 2004 12:15:51 +0000, Harag
    <> wrote:

    >
    >
    >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
    >
    >
    >On Fri, 9 Jan 2004 03:52:01 -0800, "josema"
    ><> wrote:
    >
    >>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
    Harag, Jan 9, 2004
    #5
  6. josema

    josema Guest

    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
    >
    >
    >On Fri, 09 Jan 2004 12:15:51 +0000, Harag
    ><> wrote:
    >
    >>
    >>
    >>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
    >>
    >>
    >>On Fri, 9 Jan 2004 03:52:01 -0800, "josema"
    >><> wrote:
    >>
    >>>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

    >
    >.
    >
    josema, Jan 9, 2004
    #6
  7. josema

    Harag Guest

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

    HTH

    Al.

    On Fri, 9 Jan 2004 04:33:27 -0800, "Josema"
    <> wrote:

    >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="document.form('FormNameHere').elements('TextBoxNameHere').value = this.value; ">
    ><option value="<%=Array(0)%>">money1</option>
    ><option value="<%=Array(1)%>">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...
    >
    >
    >>-----Original Message-----
    >>
    >>"josema" <> wrote in

    >message
    >>news:0a0701c3d6a6$fdf5de90$...
    >>> 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>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>
    >>.
    >>
    Harag, Jan 9, 2004
    #7
  8. josema

    Alex G Guest

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

    "josema" <> wrote in message news:<0a0701c3d6a6$fdf5de90$>...
    > 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
    Alex G, Jan 9, 2004
    #8
  9. josema

    Roland Hall Guest

    : ><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
    Roland Hall, Jan 9, 2004
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Virgil Hobbs
    Replies:
    0
    Views:
    500
    David Virgil Hobbs
    Jan 6, 2004
  2. mcdeveloper
    Replies:
    1
    Views:
    4,168
    mcdeveloper
    Jun 13, 2006
  3. CRON
    Replies:
    24
    Views:
    200,426
    Adrienne Boswell
    Jun 20, 2006
  4. Mark Rae

    JavaScript or not JavaScript

    Mark Rae, Sep 5, 2006, in forum: ASP .Net
    Replies:
    36
    Views:
    1,064
    Paul Sture
    Sep 9, 2006
  5. John Davis

    ASP JavaScript versus ASP VBScript

    John Davis, Sep 6, 2003, in forum: ASP General
    Replies:
    5
    Views:
    132
    Curt_C [MVP]
    Sep 7, 2003
Loading...

Share This Page