How to pass a variable from javascript to another ASP page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deedi
    New Member
    • May 2007
    • 11

    #1

    How to pass a variable from javascript to another ASP page

    Hi,

    I have a code like this in my first asp form

    function something()
    {
    if (confirm("do you want to continue")==tru e)

    {
    a=1
    }
    else
    {
    a=0
    }
    }
    now i want to make use of my variable a in my second asp form. Please guide me to get it.

    Thanks.
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    Deedi,

    You are going to have to pass it as either form data
    [html]<input type="hidden" name="a" value="1">[/html]
    or as querystring
    [html]<a href="secondPag e.asp?a=1">cont inue</a>[/html]
    Either one will require the use of javascript to put the data there. You might also be able to put it into a cookie. Can javascript set cookies? I don't know.

    Anyway, javascript is required regardless.

    Jared

    Comment

    • deedi
      New Member
      • May 2007
      • 11

      #3
      Hi Jared,

      I've tried with the hidden variable , but it doesn't work. When i type document.form1. the hidden varable name is not coming here. So i couldn't proceed in that way.

      The query string method worked well, however. Thanks for your answer.

      Comment

      • Dipti Singh
        New Member
        • Mar 2007
        • 20

        #4
        but through query string the value of variable will be shown to user through url.

        what will u do if u don't want to show the value to the user......

        document.form1. hiddenvalriable .value=a;
        will work. this name will not come automatically, u have to write.

        Comment

        • deedi
          New Member
          • May 2007
          • 11

          #5
          Hi Dipti,


          I've created a hidden variable as said above. But it is not reflecting when i want to use that. Don't know what is the mistake...

          Comment

          • jhardman
            Recognized Expert Specialist
            • Jan 2007
            • 3405

            #6
            For form data to be passed to the next page, a form needs to be submitted. For example, I wrote this code to post the screen resolution to the next page. When the page loads it adds the info I wanted to hidden inputs (but this would work just as well with any input type) and then submits the form.
            Code:
            <head>
            <script language="JavaScript">
            <!-- Begin
            function rP(inH, inW, frm) {
               inH.value=screen.height;
               inW.value=screen.width;
               frm.submit();
            }
            // END -->
            </script>
            </head>
            <body onload="rP(this.document.all.bob.height,
             this.document.all.bob.width,
             this.document.all.bob)">
            <form name="bob" action="test2.asp" method="post">
            <input type="hidden" name="height">
            <input type="hidden" name="width">
            </form>
            Is this similar to what you wanted to try?

            Jared

            Comment

            Working...