Solved

A Jquery Change

Posted on 2014-01-17
1
274 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 52

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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 …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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…

910 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

18 Experts available now in Live!

Get 1:1 Help Now