DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

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

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links