Solved

HTML SELECT to jQuery Spinner?

Posted on 2012-04-02
15
1,440 Views
Last Modified: 2012-06-11
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.
0
Comment
Question by:bamapie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
15 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37799602
0
 

Author Comment

by:bamapie
ID: 37801452
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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37801937
Ok I'll see what I can find or make
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37806069
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

0
 

Author Comment

by:bamapie
ID: 37809431
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.
0
 

Author Comment

by:bamapie
ID: 37813183
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!
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37813268
It just posts to the server as the original text input
0
 

Author Comment

by:bamapie
ID: 37909371
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>?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37909383
Hmm not in my implementation

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

Author Comment

by:bamapie
ID: 37986478
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()?
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 37987380
div.RightButton

<div class="RightButton"></div>
0
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 38068879
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 38068880
0
 

Author Closing Comment

by:bamapie
ID: 38070095
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
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question