Link to home
Start Free TrialLog in
Avatar of bamapie
bamapie

asked on

HTML SELECT to jQuery Spinner?

I'd like to interface my ASP.NET dropdownlist controls (which render as HTML SELECTs) a different way:  like a numeric spinner, or "updown" control.

You know, where you have up/down arrow buttons or arrow buttons to the left and right of the control area.  When you click left (or down), you move backwards through the SELECT items.  When you click right (or up) you advance forward through the SELECT items.

Everything else would function the same.

Has anyone seen anything like this?  The best solution, in my mind, would be a jQuery widget that "acts on" a SELECT and modifies that select to work in a spinner format.

You would still be able to retrieve both option.VALUE and option.TEXT from the spinner control, just like with the HTML SELECT.

I have been hammering Google and I do not believe such a thing exists, but I want to poll to make sure.

Also, I do NOT want to take the time to develop one myself.

Thanks very much.
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Avatar of bamapie
bamapie

ASKER

That looks like something that just takes a text box and converts it into a numeric spinner.

I'm talking about something that takes an HTML SELECT and changes it into a spinner--retaining all the text labels (which would be what you would see as you spin through the items).  You would not see numerics.  You'd see the same items as you populated your HTML SELECT with.
Ok I'll see what I can find or make
Here you go

http://jquery.anantanandgupta.net/plugins/jQuerySpinnerControl/demo/3/

Please download the code instead of deep linking like I did.

Note the optional hiding of the select

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="http://jquery.anantanandgupta.net/plugins/jQuerySpinnerControl/demo/3/" />
    <title>jQuery Spinner Control - Spinning List of Items</title>
    <link href="../../../Styles/SpinnerControl/jquery.spinnercontrol.css" rel="stylesheet" type="text/css" />
    <link href="../../../Styles/jquery.snippet.min.css" rel="stylesheet" type="text/css" />
    <link href="../../../Styles/SiteTemplate.css" rel="stylesheet" type="text/css" />
    <link href="../../../Styles/SpinnerControl/pluginSite.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/jquery.js" type="text/javascript"></script>

    <script src="../../../Scripts/SpinnerControl/jquery.spinnercontrol.js" type="text/javascript"></script>
    <script src="../../../Scripts/jquery.snippet.min.js" type="text/javascript"></script>
</head>
<body>
    <div class="pageContainer">
        <div class="pageHeader">
            jQuery Spinner Control - converting a select to spinners
        </div>
        <div class="pageContents">
            <div class="heading">
                Code: Spinning List of Items
            </div>
            <div id="selcontainer">
            input select: <select id="sel1">
            <option value="">Please select</option>
            <option value="Value 1">Text 1</option>
            <option value="Value 2">Text 2</option>
            <option value="Value 3">Text 3</option>
            <option value="Value 4">Text 4</option>
            <option value="Value 5">Text 5</option>
            <option value="Value 6">Text 6</option>
            <option value="Value 7">Text 7</option>
            <option value="Value 8">Text 8</option>
            <option value="Value 9">Text 9</option>
            </select>
            </div>
            <div class="heading">
                Output:
            </div>
            <div class="OutputContainer">
                <div style="float: left; overflow: auto; padding: 0 10px;">
                    <div>
                        values:</div>

                    <input type="text" id="txtValues" />
                </div>
                <div style="float: left; overflow: auto; padding: 0 10px;">
                    <div>
                        text:</div>
                    <input type="text" id="txtText" />
                </div>
            </div>
        </div>
    </div>
</body>

<script type="text/javascript">
    $(function () {
        var opts = $("#sel1 option"), list1=[], list2=[];
        $.each(opts,function(){
          var opt = $(this);
          if (opt.attr("value")) {
            list1.push(opt.attr("value"));
            list2.push(opt.text());
          } 
        });
        $("#selcontainer").hide(); // hide the select we just converted
        
        $("#txtValues").SpinnerControl({ type: 'list',
            typedata: {
                list: list1.join(",")
            },
            width: '100px',
            looping: true
        });
        $("#txtText").SpinnerControl({ type: 'list',
            typedata: {
                list: list2.join(",")
            },
            width: '100px',
            looping: true
        });
        $("pre.javascript").snippet("javascript", { showNum: false, transparent: false, style: "zellner" });
    })
</script>
</html>

Open in new window

Avatar of bamapie

ASKER

Oh, wow.  Okay, give me a day or two to find the time to plug it in and give this a shot.

Thanks!  I hope you get more mileage out of these than just me!  This could have some legs if it works.
Avatar of bamapie

ASKER

Okay.  I like how it behaves.

How do I hook the (change) event?  Like, if I need to react upon each click? (like the change event in the Html SELECT)

And how would I simply read the currently-selected .text and .value properties of this new spinner control?

Thanks!
It just posts to the server as the original text input
Avatar of bamapie

ASKER

So, if I wanted to hook the onChange() event on the client side and do something, I would just hook the onChange event of the original <select>?
Hmm not in my implementation

You (or I, if you want) need to hook
$("div.RightButton".click(...)
Avatar of bamapie

ASKER

I'm so sorry I'm just now looping back through this.

Am I reading this right, that I need to hook $('div.RightButton').click(), or is it ('divRightButton').click()?
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
Avatar of bamapie

ASKER

I'll have to try this where I can hook that click event.  That was the piece I was missing that prevented me deploying this idea previously.

Thanks