HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • asd@asd.com

    #1

    HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??

    I need to find the value/index of the previously selected item of a
    select list. That is, when the user selects an item from the list and
    a certain condition elsewhere in the form is not met, I need to
    display an alert box warning the user that a selection cannot be made,
    and redisplay the item that was previously selected. What is the most
    efficient way of doing this?

    Please email replies to tdk13@perfectso lve.com

    Thanks in advance.


  • Andrew Thompson

    #2
    Re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??

    On Mon, 08 Nov 2004 23:09:26 -0500, asd@asd.com wrote:
    [color=blue]
    > sub: Re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??[/color]

    Please don't SHOUT, especially in your subject.
    ....[color=blue]
    > Please email replies to tdk13@perfectso lve.com[/color]

    How much are you prepared to pay for this personal service?

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane

    Comment

    • RobG

      #3
      Re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??

      asd@asd.com wrote:[color=blue]
      > I need to find the value/index of the previously selected item of a
      > select list. That is, when the user selects an item from the list and
      > a certain condition elsewhere in the form is not met, I need to
      > display an alert box warning the user that a selection cannot be made,
      > and redisplay the item that was previously selected. What is the most
      > efficient way of doing this?
      >
      > Please email replies to tdk13@perfectso lve.com[/color]

      Here is a posted solution:

      Create a global array when the page is loaded. When the user selects
      each selection, put the selected item index into the array using
      push().

      If the current selection fails your test, pop the last item off the end
      of the array, the new last item in the array will be the index of the
      previous selection. You can keep poping the last one off until there
      are none left - at this point, reset the form.

      If you only want to remember the last one and not all the previous
      ones, then just set a single variable and replace it with each
      successive successful selection.

      Cheers, Rob.

      <script type="text/javascript">

      // Global array to store selection indexes
      selectedItems = new Array();

      // Adds current selection index to array
      function addCurrent(a){
      var x = a.options;
      for (var i=0;i<x.length; i++) {
      if (x[i].selected) {
      selectedItems.p ush(i);
      }
      }
      }

      function selectLast(a) {
      var x = a.options;
      if (selectedItems. length <= 1) {

      // alert is optional
      alert('No previous selection, resetting list');

      // clear array and reset form
      selectedItems.p op();
      a.parentNode.re set();
      } else {

      // clear last item from array, set selected to
      // new last item (previous index)
      selectedItems.p op();
      var p = selectedItems[selectedItems.l ength-1];
      a.options[p].selected = true;
      }
      }
      </script>
      <form action="" name="aForm"
      onchange="addCu rrent(this.optL ist1);">
      <select name="optList1" >
      <option value="opt0">
      <option value="opt1">Op tion 1
      <option value="opt2">Op tion 2
      <option value="opt3">Op tion 3
      <option value="opt4">Op tion 4
      </select>
      <input type="button" value="Back to previous"
      onclick="select Last(this.form. optList1);">
      <input type="reset">
      </form>

      Comment

      • RobG

        #4
        Re: HELP: RETRIEVING PREVIOUS VALUE FROM SELECT LIST??

        RobG wrote:
        [...][color=blue]
        > <form action="" name="aForm"
        > onchange="addCu rrent(this.optL ist1);">
        > <select name="optList1" >[/color]

        Ooops, sorry, I put the "onchange" on the wrong element. Worked fine
        in Firefox but IE barfed. Testing, testing, testing... should read:

        <form action="" name="aForm">
        <select name="optList1" onchange="addCu rrent(this);">

        As a point of interest, I hate people who yell their subject lines,
        however if I reduce it to lower case, will it still thread OK in most
        reader agents?

        Cheers, Rob.

        Comment

        • Andrew Thompson

          #5
          Re: help: retrieving previous value from select list??

          On Tue, 09 Nov 2004 06:16:41 GMT, RobG wrote:
          ...[color=blue]
          > As a point of interest, I hate people who yell their subject lines,
          > however if I reduce it to lower case, will it still thread OK in most
          > reader agents?[/color]

          (shrugs) Let's find out..

          --
          Andrew Thompson
          http://www.PhySci.org/codes/ Web & IT Help
          http://www.PhySci.org/ Open-source software suite
          http://www.1point1C.org/ Science & Technology
          http://www.LensEscapes.com/ Images that escape the mundane

          Comment

          • Andrew Thompson

            #6
            Re: help: retrieving previous value from select list??

            On Tue, 09 Nov 2004 06:35:21 GMT, Andrew Thompson wrote:
            [color=blue]
            > On Tue, 09 Nov 2004 06:16:41 GMT, RobG wrote:
            > ..[color=green]
            >> As a point of interest, I hate people who yell their subject lines,
            >> however if I reduce it to lower case, will it still thread OK in most
            >> reader agents?[/color]
            >
            > (shrugs) Let's find out..[/color]

            40tude Dialog - no. ;)

            --
            Andrew Thompson
            http://www.PhySci.org/codes/ Web & IT Help
            http://www.PhySci.org/ Open-source software suite
            http://www.1point1C.org/ Science & Technology
            http://www.LensEscapes.com/ Images that escape the mundane

            Comment

            • RobG

              #7
              Re: help: retrieving previous value from select list??

              Andrew Thompson wrote:
              [color=blue]
              > (shrugs) Let's find out..
              >[/color]

              LOL! The best chuckle I've had in quite a while... ;-)

              Rob.

              Comment

              • Michael Winter

                #8
                Re: help: retrieving previous value from select list??

                On Tue, 09 Nov 2004 06:36:24 GMT, Andrew Thompson <SeeMySites@www .invalid>
                wrote:
                [color=blue]
                > On Tue, 09 Nov 2004 06:35:21 GMT, Andrew Thompson wrote:
                >[color=green]
                >> On Tue, 09 Nov 2004 06:16:41 GMT, RobG wrote:
                >>[color=darkred]
                >>> [...] if I reduce it to lower case, will it still thread OK in
                >>> most reader agents?[/color]
                >>
                >> (shrugs) Let's find out..[/color]
                >
                > 40tude Dialog - no. ;)[/color]

                Really? Odd. Opera does.

                I thought the point of the References header was to thread messages. The
                first message id is that of the first post in the thread. The second id
                refers to the second post, and so on. Using the subject should be a fall
                back at most.

                Mike

                --
                Michael Winter
                Replace ".invalid" with ".uk" to reply by e-mail.

                Comment

                • Andrew Thompson

                  #9
                  Re: help: retrieving previous value from select list??

                  On Tue, 09 Nov 2004 10:07:24 GMT, Michael Winter wrote:
                  [color=blue]
                  > On Tue, 09 Nov 2004 06:36:24 GMT, Andrew Thompson <SeeMySites@www .invalid>
                  > wrote:
                  >[color=green]
                  >> On Tue, 09 Nov 2004 06:35:21 GMT, Andrew Thompson wrote:
                  >>[color=darkred]
                  >>> On Tue, 09 Nov 2004 06:16:41 GMT, RobG wrote:
                  >>>
                  >>>> [...] if I reduce it to lower case, will it still thread OK in
                  >>>> most reader agents?
                  >>>
                  >>> (shrugs) Let's find out..[/color]
                  >>
                  >> 40tude Dialog - no. ;)[/color]
                  >
                  > Really? Odd. Opera does.[/color]

                  I was most interested in Google, but the thread had not surfaced there yet.
                  Now that post (and the thread) have..
                  <http://google.com/groups?selm=frs lp9q1fqt8$.1rd5 c6latrv7y.dlg@4 0tude.net>

                  Follow the 'View: Complete Thread..' for the result.
                  [ Yes, Google groups threads it correctly. ]

                  If Opera and ..Mozilla Thunderbird 0.8 and OE thread it correctly,
                  I think the answer to the question is..

                  "Yes, it threads OK in (most) reader agents."

                  --
                  Andrew Thompson
                  http://www.PhySci.org/codes/ Web & IT Help
                  http://www.PhySci.org/ Open-source software suite
                  http://www.1point1C.org/ Science & Technology
                  http://www.LensEscapes.com/ Images that escape the mundane

                  Comment

                  Working...