Textfield Numeric Sorting?

Discussion in 'Javascript' started by Jared Cobb, Sep 18, 2003.

  1. Jared Cobb

    Jared Cobb Guest

    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!

    j
    Jared Cobb, Sep 18, 2003
    #1
    1. Advertising

  2. Jared Cobb wrote:
    > 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.


    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
    George M Jempty, Sep 18, 2003
    #2
    1. Advertising

  3. (Jared Cobb) writes:

    > 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!


    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.elements;
    var to = +this.value;
    var min = Math.min(current,to);
    var max = Math.max(current,to);
    var change;
    if (current < to) {
    change = -1;
    } else if (current > to) {
    change = 1;
    } else {
    return; // no change
    }
    for (var i=0;i<elems.length;i++) {
    var elemVal = +elems.value;
    if (elems != this && elemVal >= min && elemVal <= max) {
    elems.value = elemVal + change;
    }
    }
    }
    ---
    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Sep 18, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Saunders

    Re: alpha numeric sorting for dataview

    John Saunders, Jul 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,677
    John Saunders
    Jul 20, 2004
  2. Replies:
    5
    Views:
    912
    X-Centric
    Jun 30, 2005
  3. darrel
    Replies:
    4
    Views:
    792
    darrel
    Jul 19, 2007
  4. jobs

    int to numeric numeric(18,2) ?

    jobs, Jul 21, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    936
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Jul 22, 2007
  5. Replies:
    3
    Views:
    218
    Amer Neely
    Nov 22, 2006
Loading...

Share This Page