Results 1 to 9 of 9

Thread: one variable in many html pages

  1. #1
    Hi,

    I'm looking for a way to define a JS variable in one page of HTML - and then use that variable in another page of HTML.

    I haven't got any coded examples to explain this better, but the type of thing is where there is one page allowing a user to select various options. These particular selections are then remembered when the user goes to the next page (but don't need to be remembered after the user leaves the site!)

    Any help would be appreciated!!

    thanks

    Ionna

  2. #2

    Cooookies!!

    Hey ionna, welcome to the forum.

    The easiest way would be to set up a page that places a cookie on the users machine, that can be accessed throughout your site. Of course, if your users have cookies turned off, they'll be SOL, but you can post something on the site to inform them of this fact.

    I hope this helps! If you need more specifics, please post back and I'll show you some code.

    Regards,

    Jim

    "Apparently I'm insane, but one of the happy kinds!"- Wally

  3. #3
    Hey Jim,

    Thanks for the quick reply!

    The main thing that I want to do is for a mock up of a system we are building at the moment. Basically we have a database that people will be searching - The problem now is that we have a demo to show the look and feel of the site and this demo is to be functional!

    so I need a user to be able to fill in a 'form', and then, on clicking a button, get their 'results'. The functionality is (very much) limited for the demo and it works OK. It would be good though if at the top of the results page I could put in, "you searched for, 'XXXX' in the area 'XXXX'"

    I could do it the hard way - and make about 20 different HTML pages to represent every possibility, or somehow refer to the choices that the user made in the last page...

    if it's got to be cookies, then please be gentle with this novice programmer!

    help would be great

    Ionna

  4. #4
    Hey Ionna,

    If you're going to be searching a database, I'd recommend using either ASP, Perl or PHP. For the mockup pages however, cookies may work OK.

    Better than that however, I'd just use hidden form fields to send to the results page, since it's a mockup.

    Code:
    <input type="hidden" value="The name of the search page here">
    <input type="hidden" value="Any other pertintnet information">
    If you really want to try the cookies, I'll see what I can come up with. I'll need to know what the info is that you want to pass back and forth so I can organize it.

    Regards,

    Jim

    P.S. Also, what kind of a server is the system going to be running on? Unix? NT?

    P.P.S. It looks like voicebox has once again come to the rescue below Thanks voice - you the man!

    [Edited by gzazJim on 12-04-2000 at 10:18 AM]

    "Apparently I'm insane, but one of the happy kinds!"- Wally

  5. #5
    Moderator
    Join Date
    Oct 2000
    Location
    Should be used instead of document.location . Except with a small l.
    Posts
    3,224
    This can be done simply using query strings. The form you submit passes the results to the second page using the variable location.search, which can be read by the Javascript program. You can process form results like this:
    Code:
    <script>
    <!--
    var keyvals = location.search.substring(1).split("&");
    var search = new Object();
    for (var i = 0; i < keyvals.length; i++) {
      var temp = keyvals[i].split("=");
      temp[1] = temp[1].split("+").join(" "); // fix + sign bug
      search[temp[0]] = unescape(temp[1]);
    }
    // -->
    </script>
    Now all results are in an object called search and if a text element on the first page is called "query" you can print it out like this:
    Code:
    You searched for
    <script>
    <!--
    document.write(search.query);
    // -->
    </script>
    [Edited by voicebox on 05-14-2001 at 09:00 AM]
    Form Parser (pass values from one page to another):
    FAQ Entry | Original Thread | Having Problems with the script? | Put Values Back Into Another Form

    Navigation: Frame

  6. #6
    Thanks guys,

    I'll give this a go, and see what I come up with. If I've got any more questions I'll let you know.

    Oh yes, the final system will use ASP - so that's not a problem

    PS - thanks again for the help - I'm impresed :-)

  7. #7
    I must not get it. You simply place this in the htm
    You searched for <%=Request.Form("firstname")%> <%=Request.Form("lastname")%>
    in the recieving page and in the form page this
    First Name:<Input Type='text' Name='firstname' size='20'>
    Last Name:<Input Type='text' Name='lastname' size='20'>

    or maybe I missed something.
    Doug

    [Edited by lorddog on 01-25-2001 at 06:40 PM]

  8. #8
    Thanks again!

    I’ve been looking at Voicebox’s suggestion – and I’m a bit out of my depth! But I figured that the only way I’ll learn is to try to work it out for myself.

    I understand that it is putting all the results from the first page into an object, which can then be called from the second page, and I’m OK with calling the information once it is in the object. The thing I can’t work out is how the results are being processed to get them into the object… I think it’s taking strings, splitting them up and putting them into a new object but other than that I’m lost :-0

    All hints – suggestions – help appreciated

    Ionna

  9. #9
    Moderator
    United States Arielladog's Avatar
    Join Date
    Mar 2000
    Location
    SF Bay Area
    Posts
    3,003
    If you are using ASP, I'd use ASP. However, if you want to use JavaScript, youc an look at this other forum topic dealing with this (like voicebox's solution):

    http://www.webxpertz.net/forums/show...p?threadid=597

    aDog

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Passing a variable between pages
    By Cat in forum Client-side forum
    Replies: 6
    Last Post: 31st May 2004, 00:57
  2. passing a variable between pages
    By tkk in forum Client-side forum
    Replies: 2
    Last Post: 12th November 2002, 04:40
  3. HELP ! I need pass variable between html pages
    By emerac in forum Client-side forum
    Replies: 1
    Last Post: 31st October 2001, 00:09
  4. Passing a variable between pages
    By jamesc in forum Client-side forum
    Replies: 5
    Last Post: 8th February 2001, 02:53

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
  •