Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2005

    Unanswered: ASP and Javascript

    I need to check a ASP variable value in a Javascript function , how do i do this?

  2. #2
    Join Date
    Nov 2002
    Houston, Texas
    Very easy, I do it all the time.

    If you're using a form, just put the ASP variable into a hidden field and then have javascript check the value in the hidden field.

    <form name="formName" id="formName">
    <input type="hidden" name="varASP" id="varASP" value="<%= the.ASPvariable %>">

    Then just have your Javascript read it normally:

    var checkMe = document.forms['formName'].varASP.value;


    A shorter way is to just skip the form (but it's useful to mention that first because most of the times I need to check an ASP variable it's usually for a form) and reference the ASP variable directly in the javascript:

    var checkMe = "<%= the.ASPvariable %>";

    Note the quotes around the ASP code. That's pretty important.

    Good luck!

  3. #3
    Join Date
    Jun 2003
    And for the same kind of answer in other words (that hopefully might give you some more ideas along the same lines):

    It's easy to use the value of a VBScript variable in JavaScript:
    document.writeln('<%= MyVBScriptVariable %>');

    It's also easy to use the value of a VBScript function in javascript:
    document.writeln('<%= MyVBScriptFunction() %>');

    Or 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>"
    J. Paul Schmidt, Freelance Web and Database Developer
    Access Database Sample, Web Database Sample, ASP Design Tips

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts