Solved

jquery autocomplete extender

Posted on 2016-08-19
7
55 Views
Last Modified: 2016-09-02
i have  ajquery autocomplete extender , and i need once i seleect a value i need to select max 5 values.how to do this restriction
0
Comment
Question by:pamela rizk
[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
  • 3
  • 3
7 Comments
 
LVL 43

Expert Comment

by:zephyr_hex (Megan)
ID: 41762953
You can do the restriction in your SQL query.  Use 'TOP 5'.  You will probably want to have some kind of ORDER BY OR WHERE clause criteria so you can properly identify what records are the top 5.

SELECT TOP 5 MyField
From MyDatabase
WHERE ...
ORDER BY ...

Open in new window

0
 
LVL 1

Expert Comment

by:brianmfalls
ID: 41763023
Or (Oracle)
Select MyField
FROM MyDatabase
WHERE ....
AND ROWNUM <= 5
ORDER BY  ...

Open in new window

0
 

Author Comment

by:pamela rizk
ID: 41763753
no i don't want that
0
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
LVL 43

Expert Comment

by:zephyr_hex (Megan)
ID: 41765480
Can you please clarify what you do want?  

You said you want the max 5 results.  That is ALL we know.  I've given a solution that will give you the max 5 results.
0
 

Author Comment

by:pamela rizk
ID: 41766357
sure thank you
what i want is that i want when i select a value from autocomplete extender, i need to manage a counter and each time user select a value the counter will be incremented and once it reaches 5 a message will be displayed
0
 
LVL 43

Accepted Solution

by:
zephyr_hex (Megan) earned 500 total points
ID: 41767209
To accomplish this, you can use a hidden field that tracks the number of selections, and display a message when it reaches 5.

Here is a Fiddle Demo.

Given the following HTML

<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags">
</div>
<input type="hidden" id="hCount" value="0">
<span id="msg"></span>

Open in new window


The jQuery looks like:

  $(function() {
    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $("#tags").autocomplete({
      source: availableTags,
      select: function(event, ui) {
        var num = parseInt($('#hCount').val());
        $('#hCount').val(num + 1);
        if ((num + 1) === 5) {
          $('#msg').text('You have selected 5');
        }
      }
    });
  });

Open in new window

0
 

Author Closing Comment

by:pamela rizk
ID: 41781150
thank you it solved my issue
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

738 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