Solved

A Jquery Change

Posted on 2014-01-17
1
278 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
[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
1 Comment
 
LVL 57

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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

737 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