0

Jquery how to iterate and get value from hidden array of fields name="tag[]"

I am using following tagedit plugin but could not found the method how to get tokenzie values.

http://tagedit.webwork-albrecht.de/

<ul id="sel_rc" class="no-bulls">
<li>
<ul class="tagedit-list ">
<li class="tagedit-listelement tagedit-listelement-old">
<span dir="ltr">none</span>

   <input type="hidden" value="none" name="tag[]">

<a class="tagedit-close" title="Remove from list.">x</a>
</li>
<li class="tagedit-listelement tagedit-listelement-old">
<span dir="ltr">r2</span>

   <input type="hidden" value="r2" name="tag[]">

<a class="tagedit-close" title="Remove from list.">x</a>
</li>

</ul>

3 Answers 3

1

Not sure if [] are valid in an attribute value, try this:

var hiddenValues = $('input[type="hidden"][name^="tag"]').map(function(){
    return this.value;
}).get();
Sign up to request clarification or add additional context in comments.

1 Comment

this is more efficient way to do it.
1

You can iterate them like any other element:

$("[name='tag[]']").each(function() {
   console.log($(this).val()); // none, r2
});

Comments

1

You can use attribute selector [attribute='value'] . And you can iterate them using jQuery each() method

$('input[name="tag[]"]').each(function(){
      console.log(this.value); 
});

Fiddle Demo

Comments

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.