www.webdeveloper.com
Results 1 to 9 of 9

Thread: [RESOLVED] Retriving variables to next page by using javascript

  1. #1
    Join Date
    Apr 2010
    Posts
    5

    resolved [RESOLVED] Retriving variables to next page by using javascript

    I have a jsp page called display.jsp ,where i have a hyperlink which redirects to a HTML page called check.html.

    display.jsp
    Code:
    %@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <% String FromAdd= "delhi";
    session.setAttribute("from" , FromAdd);
    String ToAdd = "agra";
    session.setAttribute("to" , ToAdd);
    %>
    <a href="check.html"  >Click here </a>
    </body>
    </html>
    .....................................................................
    check.html

    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    <script type="text/javascript"> 
    function intialize()
    {
    
    
    here temme hw i can retrive the values of FromAdd and ToAdd  form abv page and display them 
    
    
    
    }
    </script>
    </head>
    <body onload="initialize()">
    
    </body>
    </html>
    so what i want to know is how i can retrive the values of FromAdd and ToAdd from check.html's javascript funt ..i.e intialize();

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    var from = '<&#37; (String) session.getAttribute("from"); %>';

  3. #3
    Join Date
    Apr 2010
    Posts
    5
    thnk for d reply fang ...but i m stil facing a prblm.
    first of all my 2nd page is a html file where the tags <% %> wouldnt work
    more over i even tried it using jsp,it gave a error saying :

    Multiple annotations found at this line:
    - Syntax error, insert "AssignmentOperator Expression" to complete
    Assignment
    - Syntax error, insert ";" to complete BlockStatements

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Afaik JavaScript can't access the session variables directly. Why not use cookies?

  5. #5
    Join Date
    Apr 2010
    Posts
    5
    well ..m new to javascript clould u just help me about telling me how to use cookies in java script so that i can retrive values from previous page

  6. #6
    Join Date
    Feb 2009
    Location
    UK
    Posts
    142
    I was trying to do this and cookies would have been my next move but a different project hove into view. I still don't know how to use cookies properly. But it looks the way to co.

    I did consider using the status line but that seems to be very iffy across the Browser spectrum. & I have been using it for adverts/date info for many years. see http://cresby.com

  7. #7
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654

  8. #8
    Join Date
    Apr 2010
    Posts
    5
    thank will check that n let u knw if i cld succesfully do it

  9. #9
    Join Date
    Apr 2010
    Posts
    5
    hey i got it ...used ur first technique i.e by sending <%=(String)session.getAttribute("from")%> into the javascript function as a parameter .and ye i did altr the code a little ... called the functions directly from the body tag by onload.

    Thank for all ur help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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



Recent Articles