JavaScript How to get hidden field array values? hidden field array rails,hidden field array,hidden field array

I have multiple hidden fields of the form

<input type="hidden" class="mail-contacts" name="to[]" value="abc1">
<input type="hidden" class="mail-contacts" name="to[]" value="abc2">
<input type="hidden" class="mail-contacts" name="to[]" value="abc3">

Number of hidden fields can be different for different cases. How can I get the values of these hidden fields ? As this is an array so can't get it with

document.getElementById('')

I need to get the values of these hidden fields and then pass it as query parameter. Please help me out. How can I do this?

Answer:1
 document.getElementsByName("hiddenfieldsname")

use above function , this wil return you the array of elements with same name

Answer:2

jQuery:

<script type='text/javascript' src='http://code.jquery.com/jquery-latest.min.js'>
<script type='text/javascript'>
    var lst_to = [];
    $("input:hidden.mail-contacts").each(function() {
        lst_to.push($(this).val());
    });
    var str_query = "?to=" + lst_to.join();
</script>

jsFiddle

Answer:3

You could do something like this:

var array = getElementsByClassName("mail-contacts");
for(i = 0; i < array.length; i++) {
    array[i]
}
Answer:4

If you are using jQuery, try this:

var arrayValues = $('input:hidden.mail-contacts').map(function(){
                      return $(this).val()
                  }).get();
Answer:5

if I'm passing a jquery object that I know is a select object, how can I get the text (not the value) of the option that is selected? I'm needing something like this. ...function ($select){ var ...

if I'm passing a jquery object that I know is a select object, how can I get the text (not the value) of the option that is selected? I'm needing something like this. ...function ($select){ var ...

  1. text value selected jquery
  2. text value selected
  3. text box value selected in javascript
  4. selectlistitem text value selected
  5. input text value selected
  6. textarea value selected
  7. jquery get text value selected option
  8. get text selected value dropdown jquery
  9. html input text value selected
  10. get text selected value dropdown javascript
  11. get text selected value jquery
  12. text value of a selected option
  13. text box selected value
  14. get text value of selected option javascript
  15. jquery text value of selected option
  16. selected text value javascript
  17. get text value of selected option

I need to eval a function kept as string and then use it in JS code, here's the scenario: Step 1 <textarea id="function_text">function test(e){ alert(e.id); }</textarea> Step 2 var ...

I need to eval a function kept as string and then use it in JS code, here's the scenario: Step 1 <textarea id="function_text">function test(e){ alert(e.id); }</textarea> Step 2 var ...

I am trying to create a simple modal using twitter bootstrap. The function of that modal is to take the name of the link clicked on, and use that name as a header. Each of the names are in a Django ...

I am trying to create a simple modal using twitter bootstrap. The function of that modal is to take the name of the link clicked on, and use that name as a header. Each of the names are in a Django ...

  1. passing data to bootstrap modal
  2. passing data to bootstrap modal angularjs
  3. passing data to bootstrap modal angular 2
  4. passing data to ngx-bootstrap modal
  5. passing data to modal bootstrap 4
  6. passing data to modal bootstrap 3

I started Android Studio in my newly updated OS X (Mavericks now). Now in Android Studio (also just updated btw) I get a message "error running git" Error:Abnormal build process termination: ...

I started Android Studio in my newly updated OS X (Mavericks now). Now in Android Studio (also just updated btw) I get a message "error running git" Error:Abnormal build process termination: ...

  1. error abnormal build process termination