Textfield Numeric Sorting?

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

    Textfield Numeric Sorting?

    Hi all

    I'm looking for a way to sort a recordset based on a numerical value. I'm
    better with examples rather than explaining, so please see the following:



    Hopefully that example explains it all. I've searched for tutorials on
    something like this but I think it's too specialized to find anything. Any
    help or a point in the right direction would be GREATLY appreciated.
    Thanks!

    j
  • George M Jempty

    #2
    Re: Textfield Numeric Sorting?

    Jared Cobb wrote:[color=blue]
    > Hi all
    >
    > I'm looking for a way to sort a recordset based on a numerical value. I'm
    > better with examples rather than explaining, so please see the following:
    >
    > http://www.jaredcobb.com/example
    >
    > Hopefully that example explains it all. I've searched for tutorials on
    > something like this but I think it's too specialized to find anything. Any
    > help or a point in the right direction would be GREATLY appreciated.[/color]

    After looking at your page, these are my first few tips:

    Change the name of the input box named "textfield" to "textfield1 ".
    this will make it easier to parse the name of the element for it's
    position in the form, if that's the approach you want to take. You
    might be able to determine position using the form.elements array,
    unless you put other fields in your form. In any event, "textfield1 " is
    more consistent giving your current naming scheme.

    Speaking of a form, make sure you are indeed using a bona fide form,
    with opening and closing <form> tags. this will allow you to have an
    onblur event handler for each text input box that can be called like this:

    onblur="reorder (this)"

    "this" refers to the text element, but will also allow you to refer to
    the form as "this.form" , which will allow you to get at all the other
    elements.

    onfocus of any field I would create an array based on the existing
    content of the form. onblur the first thing I would do is validate the
    user's input. Having created my array onfocus it will be easy to
    replace invalid input.

    Hope this helps, even though its only a bunch of housekeeping BEFORE you
    actually get to sorting your data.

    /G

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: Textfield Numeric Sorting?

      google@jaredcob b.com (Jared Cobb) writes:
      [color=blue]
      > Hi all
      >
      > I'm looking for a way to sort a recordset based on a numerical value. I'm
      > better with examples rather than explaining, so please see the following:
      >
      > http://www.jaredcobb.com/example
      >
      > Hopefully that example explains it all. I've searched for tutorials on
      > something like this but I think it's too specialized to find anything. Any
      > help or a point in the right direction would be GREATLY appreciated.
      > Thanks![/color]

      I'll assume there is a form around the input elements.

      Whenever you change one number, from a to b, all other numbers between
      a and b must change too.

      I suggest putting these two handlers on the input elements onfocus and
      onchange handlers.
      ---
      var current;

      function focus(){
      current = +this.value;
      }
      function change() {
      var elems = this.form.eleme nts;
      var to = +this.value;
      var min = Math.min(curren t,to);
      var max = Math.max(curren t,to);
      var change;
      if (current < to) {
      change = -1;
      } else if (current > to) {
      change = 1;
      } else {
      return; // no change
      }
      for (var i=0;i<elems.len gth;i++) {
      var elemVal = +elems[i].value;
      if (elems[i] != this && elemVal >= min && elemVal <= max) {
      elems[i].value = elemVal + change;
      }
      }
      }
      ---
      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      Working...