1

I have this code

<input type="hidden" value="[{"value":1,"label":"Emmoia Boently"},{"value":6,"label":"John Smith"}]" name="group[users][]" id="users">

<input type="text" value="Emmoia--Boently, John--Smith, " name="autocompleter_group[users][]" id="autocompleter_userss" class="ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">

Now my problem is the current javascript is adding the values from textbox to the hidden feilds.

But when i delete the text then it don't deletes from the hidden input fields.

So i want to do in jquery that when i start deleting the text in main textbox then the value gets deleted in the hidden input field as well.

just like we do in SO when we delete the tag characters in ask question page

3
  • 1
    Any code? How you add values and trying to remove them? Commented Sep 13, 2012 at 15:57
  • To start, you've got your quotes messed up in the example. Second, why not just re-set the hidden field's value to the current representation of the textbox. This would be much simpler than trying to parse out which value got deleted. Commented Sep 13, 2012 at 15:59
  • i am using jquery autocomplete plugin Commented Sep 13, 2012 at 16:05

2 Answers 2

3
$("#autocompleter_userss").on("keyup", function() {
    $("#users").val($(this).val());
});

Fiddle

Sign up to request clarification or add additional context in comments.

Comments

1

UPDATE: Seems like you're looking for a tag editor. See this post for exhaustive links :)


$('input#1').change(function(){
  $('input#hidden').val($(this).val());
});

Additionally, you could try some data-binidng libaries like knockout.js among others.

2 Comments

its not that simple. In the hidden box i have the ids and text but in the text box i have only text , which i get via AJAX autocomplete call. I think i some how need to have cross button to delete the values
@volcano: Now I get your question. See my update. Try this one and this one to check if you've found what you were searching :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.