SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast hombre_de_las_ca's Avatar
    Join Date
    Apr 2005
    Location
    Bangalore, India
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Javascript -> ASP

    can anyone tell me how to pass a value stored in a javascript function to an ASP variable when onchange event executes for a list box inside an ASP page without rerfreshing the page!!!
    For Example:
    if i want to pass the value of varchar to a variable Zoom defined in the ASP page on onchange event of a list box inside an asp page(even to a hidden field in the page) how will i do it !!

    <%

    dim Zoom

    %>


    function func()
    {
    var varchar
    varchar = "aaa"
    }

  2. #2
    SitePoint Wizard HarryR's Avatar
    Join Date
    Dec 2004
    Location
    London, UK
    Posts
    1,376
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One way you can do this is to dynamicly write out the client-side javascript, or use XmlHttpRequest.

    Obviously writing out the javascript is easiest, as shown in my example:

    Code:
    <%
     Dim whatever
     whatever = "abc"
    %>
    <script language="JavaScript">
      function helloWorld ()
      {
        alert("<%= whatever %>");
       }
    </script>

  3. #3
    SitePoint Guru momos's Avatar
    Join Date
    Apr 2004
    Location
    Belgium
    Posts
    919
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    put the value of the javascript in a hidden-field(input), and when you submit your site, you'll find it in the request-object.

    hope this helps...

  4. #4
    SitePoint Enthusiast hombre_de_las_ca's Avatar
    Join Date
    Apr 2005
    Location
    Bangalore, India
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Red face

    i have no idea how to put the value from the javascript into a hidden field...could u help me with that!!!

  5. #5
    SitePoint Guru momos's Avatar
    Join Date
    Apr 2004
    Location
    Belgium
    Posts
    919
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    something like:
    document.getElementById(/*the id of the input type hidden*/).value="aaa";

    then submit your form, and now you have your variable...

  6. #6
    SitePoint Enthusiast hombre_de_las_ca's Avatar
    Join Date
    Apr 2005
    Location
    Bangalore, India
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks Momos...it worked... : )
    CaveMan


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
  •