javascript - jQuery checked checkbox value shown in input textbox and uncheck will remove -
I am trying to find a solution as stated in my headline that when you have multiple checkboxes and when You check the checkbox will be paired with a value like "blood" in an input text box. Each checked value in the text box will be separated with space or comma. When you uncheck a checkbox, the value corresponding to it will be removed from the textbox.
The closest example I have ever given is:
I have tried & lt; Input type = "text" name = "text" id = "result" value = "" and>
and $ li.text to change the code around a bit (This.value);
to $ li.val (this.value);
but nothing appears. Unfortunately, Jackie I do not know.
If possible, please enter some light?
What can you do?
var arr = []; $ ('Input Input'). Change (function () (if checked) {arr.push (this.value);} and {arr.splice (arr.indexOf (this.value), 1);} $ ('# Target'). Val (arr + '');));; LET; DOCTYPE html> gt; top & gt; script src = "http://code.jquery.com /jquery-latest.js "> & gt; Title & gt; JS bin & lt; / title & gt; & Lt ; / Head> gt; body & gt; div id = "input" & gt; & lt; input type = "checkbox" value = "apple" & gt; & gt; input type = "checkbox "Value =" orange "> Gt;
Comments
Post a Comment