Save the choice made from a Drop/dwon menu?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JS

    Save the choice made from a Drop/dwon menu?

    I have two drop/down menus that are dependant on each other. When I have
    made a choice in both of these menus and press a button I get to a page
    depending on the choice made. On this page there is two buttons "Accept" and
    "Back".

    When I press "Back" I would like to get back to the page with the two menus
    and they should be set to the choice I made. Now the just reset when I press
    the "Back" button.

    Is it possible to save the options that I choose from the drop/down menus
    when I get back to them by pressing "Back"??


  • McKirahan

    #2
    Re: Save the choice made from a Drop/dwon menu?

    "JS" <dsa.@asdf.co m> wrote in message news:d82jel$qkr $1@news.net.uni-c.dk...[color=blue]
    > I have two drop/down menus that are dependant on each other. When I have
    > made a choice in both of these menus and press a button I get to a page
    > depending on the choice made. On this page there is two buttons "Accept"[/color]
    and[color=blue]
    > "Back".
    >
    > When I press "Back" I would like to get back to the page with the two[/color]
    menus[color=blue]
    > and they should be set to the choice I made. Now the just reset when I[/color]
    press[color=blue]
    > the "Back" button.
    >
    > Is it possible to save the options that I choose from the drop/down menus
    > when I get back to them by pressing "Back"??
    >[/color]

    Here's one solution. Watch for word-wrap.

    << page1.htm >>

    <html>
    <head>
    <title><title>p age1.htm</title>
    <script type="text/javascript">
    function submits(form) {
    var form = document.form1;
    var ind1 = form.sel1.selec tedIndex;
    var ind2 = form.sel2.selec tedIndex;
    if (ind1 == 0 || ind2 == 0) return false;
    var sel1 = form.sel1.optio ns[ind1].value;
    var sel2 = form.sel2.optio ns[ind2].value;
    document.action += "?" + sel1 + "&" + sel2;
    return true;
    }
    function selects() {
    var qstr = location.search ;
    if (qstr.length < 4) {
    alert("Invalid QueryString!");
    return;
    }
    var form = document.form1;
    qstr = qstr.substr(1);
    var pair = qstr.split("&") ;
    for (var i=0; i<pair.length; i++) {
    var item = pair[i].split("=");
    if (i == 0) {
    for (var j=1; j<form.sel1.len gth; j++)
    if (form.sel1.opti ons[j].value == item[1]) {
    form.sel1[j].selected = true;
    }
    }
    if (i == 1) {
    for (var j=1; j<form.sel2.len gth; j++)
    if (form.sel2.opti ons[j].value == item[1]) {
    form.sel2[j].selected = true;
    }
    }
    }
    }
    </script>
    </head>
    <body onload="selects ()">
    <form action="page2.h tm" method="get" name="form1" onsubmit="retur n
    submits()">
    <br>
    <select name="sel1">
    <option value="" selected>
    <option value="1">One
    <option value="2">Two
    <option value="3">Three
    </select>
    <br>
    <select name="sel2">
    <option value="" selected>
    <option value="a">A
    <option value="b">B
    <option value="c">C
    </select>
    <br>
    <input type="Submit" value="Submit">
    </form>
    </body>
    </html>


    << page2.htm >>

    <html>
    <head>
    <title>page2.ht m</title>
    <script type="text/javascript">
    function backs() {
    location.href = "page1.htm" + location.search ;
    }
    function texts() {
    var qstr = location.search ;
    if (qstr.length < 4) return;
    var form = document.form1;
    qstr = qstr.substr(1);
    var pair = qstr.split("&") ;
    for (var i=0; i<pair.length; i++) {
    var item = pair[i].split("=");
    if (i == 0) form.sel1.value = item[1];
    if (i == 1) form.sel2.value = item[1];
    }
    }
    </script>
    </head>
    <body onload="texts() ">
    <form action="page3.h tm" method="get" name="form1">
    <br>
    <input type="text" name="sel1" readonly>
    <br>
    <input type="text" name="sel2" readonly>
    <br>
    <input type="submit" value="Accept">
    <input type="button" value="Back" onclick="backs( )">
    </form>
    </body>
    </html>

    << page3.htm >>

    <html>
    <head>
    <title>page3.ht m</title>
    </head>
    <body>
    <b>Accepted</b>
    </body>
    </html>


    Comment

    • Ivo

      #3
      Re: Save the choice made from a Drop/dwon menu?

      "JS" <dsa.@asdf.co m> wrote in message news:d82jel$qkr $1@news.net.uni-c.dk...[color=blue]
      > I have two drop/down menus that are dependant on each other. When I have
      > made a choice in both of these menus and press a button I get to a page
      > depending on the choice made. On this page there is two buttons "Accept"
      > and "Back".
      > Is it possible to save the options that I choose from the drop/down menus
      > when I get back to them by pressing "Back"??[/color]

      What is the code behind that Back button (and why do you need one when all
      known browsers provide the very thing with plenty of prominence)? If it is
      to be the same on each of those selectable pages, the code probably looks
      quite generic, like

      onclick="histor y.go(-1)"

      and you need to resort to setting cookies on the originating page:

      <select onchange=" dostuff(); alsosetacookie( ); ">

      For example http://4umi.com/web/css/changesheet.htm
      contains some hilited cookie writing and reading code.

      But if you can code specific url's on specific pages (a serverside script
      perhaps?), something like

      onclick="locati on.href='lastpa ge.html?a=5&amp ;b=7';"

      then you can read which option to select in which list from the url.
      A quick n dirry approach, with a and b being references to the
      respective <select> boxes:

      var s = window.location .search;
      if( (i = s.match( /a=(\d+)/ ) ) ) {
      a.options[ i[1] ].selected=true;
      }
      if( (i = s.match( /b=(\d+)/ ) ) ) {
      b.options[ i[1] ].selected=true;
      }

      should get you on the way...

      hth
      Ivo


      Comment

      • McKirahan

        #4
        Re: Save the choice made from a Drop/dwon menu?

        "McKirahan" <News@McKirahan .com> wrote in message
        news:CPqdnZOHq8 hXcTnfRVn-gA@comcast.com. ..[color=blue]
        > "JS" <dsa.@asdf.co m> wrote in message[/color]
        news:d82jel$qkr $1@news.net.uni-c.dk...[color=blue][color=green]
        > > I have two drop/down menus that are dependant on each other. When I have
        > > made a choice in both of these menus and press a button I get to a page
        > > depending on the choice made. On this page there is two buttons "Accept"[/color]
        > and[color=green]
        > > "Back".
        > >
        > > When I press "Back" I would like to get back to the page with the two[/color]
        > menus[color=green]
        > > and they should be set to the choice I made. Now the just reset when I[/color]
        > press[color=green]
        > > the "Back" button.
        > >
        > > Is it possible to save the options that I choose from the drop/down[/color][/color]
        menus[color=blue][color=green]
        > > when I get back to them by pressing "Back"??
        > >[/color][/color]

        Can you use ASP -- it would be a lot easier to do it server-side!


        Comment

        Working...