pass data from asp to javascript in the same page


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: pass data from asp to javascript in the same page

Hybrid View

  1. #1
    Tim Guest

    pass data from asp to javascript in the same page


    How can I pass ASP variables to javascript variables
    (in the same page)?

    Thanx in advance.
    Tim

  2. #2
    J. Paul Schmidt Guest

    Re: pass data from asp to javascript in the same page


    Here is an example which puts the value of a VBScript variable into a JavaScript
    alert box:

    Response.Write "<script language='JavaScript'>alert('The value is " & MyVBScriptVariable
    & "');</script>"

    Best regards,
    -Paul

    J. Paul Schmidt, MBA
    Databases on the Web
    http://www.Bullschmidt.com



  3. #3
    Dylan Guest

    Re: pass data from asp to javascript in the same page


    Hi Tim,

    Here is a simple way to use a variable declared in ASP in JavaScript:

    <%

    Dim varASP 'a variable in asp
    varASP = "Some value"
    %>

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function ShowValue() {
    window.alert('<% = varASP %>')
    }
    -->
    </SCRIPT>

    Just make sure that the asp variable is declared and initialized before being
    used in the JavaScript part.

    Hope this one helps !
    Dylan.

    "Tim" <sam213@cdg.com> wrote:
    >
    >How can I pass ASP variables to javascript variables
    >(in the same page)?
    >
    >Thanx in advance.
    >Tim



  4. #4
    Rohit Wason Guest

    Re: pass data from asp to javascript in the same page


    Yes,
    All above methods work fine, but I still believe in:

    <SCRIPT Language="JavaScript">
    varName = "<%=strName%>"
    ...
    ...
    </SCRIPT>

    This actually 'copies' the variable to client side that can be 'used' anywhere
    in client side

    Cheers
    Rohit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center