Solved

A Jquery Change

Posted on 2014-01-17
1
273 Views
Last Modified: 2014-01-18
i had a code which needs little modification,

working fine, but the only change required is to uncheckbox the selected checkbox if the value of the first textbox is changed and select the checkbox whose value is entered then

here is code for that

jquery UI and jquery 1.9.2 is already included

$(function () {
    var cbv;
    var detect = ["AcC", "Fridge", "Washing", "Almirah"];

    $("#inputfields").autocomplete({
        source: detect,
        select: function (event, ui) {
            var txt = (ui.item.value);
            $("#inputfields").val(txt);
            var inputdetect = $("#inputfields").val(txt);
            cbv = inputdetect.val();
            $("#" + cbv + "").attr("checked", true);

        },
        change: function () {
            $("#" + cbv + "").attr("checked", false);


        }
    });
});

<section>
    <label for="inputfields">Choose:</label>
    <input id="inputfields" />
    <br>
    <input type="checkbox" id="AcC">
    <label>AcC</label>
    <br>
    <input type="checkbox" id="Fridge">
    <label>Fridge</label>
    <br>
    <input type="checkbox" id="Washing">
    <label>Washing</label>
    <br>
    <input type="checkbox" id="Almirah">
    <label>Almirah</label>
</section>

Open in new window

0
Comment
1 Comment
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39790365
Just add this line
$(function() {
    var cbv;
    var detect = ["AcC", "Fridge", "Washing", "Almirah"];

    $("#inputfields").autocomplete({
        source: detect,
        select: function (event, ui) {
            var txt = (ui.item.value);
            $("#inputfields").val(txt);
            var inputdetect = $("#inputfields").val(txt);
            cbv = inputdetect.val();
            /*** ADD THIS ***/
            $('input:checked').attr('checked', false);
            $("#" + cbv + "").attr("checked", true);

        },
        change: function () {
            $("#" + cbv + "").attr("checked", false);


        }
    });
});
</script>

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
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)

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now