Results 1 to 4 of 4

Thread: passing Variables in HTML URL

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    72

    Question passing Variables in HTML URL

    Ok this is probably a really basic thing... but for some reason I can't find any documentation on it (maybe its so basic ppl assume that it should be known =)

    Anyway, I know you can pass .asp pages variables and retrieve thrm thru the request.form("BLAH").. or request.servervariables...

    BUT, I am wondering if it is possible to pass an .html page variables and somehow get them out with JavaScript.


    Basically I have some buttons that i want to reference the original page they were created on, but will add a variable to allow the JavaScript at the top to redirect the page properly within a parent frame. (kind of a pain... but it should work as long as I can pass vars to an .html page).

    Thanks!

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Posts
    72
    That's almost what i need...

    I think I didn't explain this right..

    Actually its a graphical image that has an href tag that will resolve to the page with the send variables.

    I saw that you can create hidden forms a while back, but not sure how I can populate a form within an href... well actually I am sure you can't.

    Just to be sure here is what I am doing currently:

    Code:
    <a href="wcDCM.asp?WCI=ItemDisplay&ID=wc@pkID&Action=Buying" target="rframe"><img src="images/wiz_search.gif" width="191" height="57" border="0"></a>

    this displays the info in the wrong frame, so I want to do something like this:

    Code:
    <a href="home.htm?ID=wc@pkID&Action=openBuying" target="rframe"><img src="images/wiz_search.gif" width="191" height="57" border="0"></a>
    and then once the page opens it will run this Javascript code:

    Code:
    <script language='JavaScript'>
       // Problem:  How to pass values to non-asp pages
    
       var passedVar_ID;
       var passedVar_Action;
       var newFrameLocation;
       passedVar_ID = "????";  // document call so that we can extract perameters passed   
       passedVar_Action = "????";  // document call so that we can extract perameters passed
       
       switch (passedVar_Action)
    	{
        	case "openDefault":
        		newFrameLocation = "wcDCM.asp?WCI=ItemDisplay&ID="    		
    			newFrameLocation = newFrameLocation + passedVar_ID;
        		newFrameLocation = newFrameLocation + "&Action=Default";			
        	break;
    
        	case "openBuying":
        		newFrameLocation = "wcDCM.asp?WCI=ItemDisplay&ID="    		
    			newFrameLocation = newFrameLocation + passedVar_ID;
        		newFrameLocation = newFrameLocation + "&Action=Buying";			
        	break;
    		
        	case "openListing":
        		newFrameLocation = "wcDCM.asp?WCI=ItemDisplay&ID="    		
    			newFrameLocation = newFrameLocation + passedVar_ID;
        		newFrameLocation = newFrameLocation + "&Action=Listing";			
        	break;
    		
        	case "openSelling":
         		newFrameLocation = "wcDCM.asp?WCI=ItemDisplay&ID="    		
    			newFrameLocation = newFrameLocation + passedVar_ID;
        		newFrameLocation = newFrameLocation + "&Action=Selling";			
        	break;
    	}
       parent.frames[1].location=newFrameLocation;  // WORKS!  Refreshes right page
    
    </script>
    So basically this all hinges on me being able to pass variables to an html page from the href.

  4. #4
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    Code:
       passedVar_ID = "????";  // document call so that we can extract perameters passed   
       passedVar_Action = "????";  // document call so that we can extract perameters passed
    
    becomes:
    
       passedVar_ID = "<%= request.form("ID")%>";    
       passedVar_Action = "<%= request.form("Action")%>";
    What you are doing is dynamically altering your JavaScript using ASP. Always keep in mind that ASP does it's thing before any JavaScript gets executed. In other words if JavaScript is doing its thing, ASP has long since died and when ASP is doing its thing, JavaScript has yet to be born.

    Another thing to remember is it's easy to get an ASP variable into a JavaScript variable as I've shown above. It's harder to get a JavaScript variable into ASP. However, I'll show you how to do it: The way I do it these days is I build a generic IFRAME on the page:
    <IFRAME SRC="" name="exec" width=1 height=1>
    which is completely invisible. Then say I need to set a session variable to a value that exists in JavaScript (we'll call it x and we'll store it in sess_x) then I issue the following command in JavaScript:

    Code:
    exec.location.href = "setsession.asp?session_name=sess_x&val=" + x;
    Then you need a tiny generic ASP script called setsession.asp that you can use whenever you need to move a JavaScript variable to ASP:

    Code:
    <%
      session_name = request.form("session_name")
      val = request.form("val")
      session(session_name) = val
    %>
    What it does is JavaScript forces ASP to run a quick process on the side in a little invisible window without interrupting the executing JavaScript in the main window. Later when other ASP programs execute, they can get access to the session variables that were temporarily set.

    (Note that there are some potential problems with this scheme for IE browsers older than 5.5)

    There, now you can move javascript variables from ASP and back again. I use this same approach in JSP as well.

    cudabean
    Last edited by Cudabean; May 10th, 2002 at 08:46 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width