Get hidden jquery field value?

I have the following HTML

<input type="hidden" name="conf1" value="7th IEEE/IFIP International Conference on Embedded and Ubiquitous Computing (EUC-09)">
    <input type="hidden" name="conf2" value="IEEE International Symposium on Parallel and Distributed Processsing with Applications">
    <input type="hidden" name="conf3" value="jkhga">
    <input type="hidden" name="conf4" value="test">
    <input type="hidden" name="conf5" value="The 3rd International Conference on Adaptive Business Information Systems (ABIS'09)">

    <input type="text" name="published">

And I'm trying to get the values ​​of hidden fields in an array using jquery. Here is what I tried:

 var conferences = new Array();

        conferences[0] = $('#conf1').val();
        conferences[1] =$("[name='conf2']").val();
        conferences[2] =$("[name='conf3']").val();
        conferences[3] = $("[name='conf4']").val();
        conferences[4] =$("[name='conf5']").val();     

Can someone guide me on how to read them?
Thanks in Advance
Dean

+5
source share
6 answers

If you are going to use jQuery, you can do this:

var array = $('input:hidden').map(function() {
    return this.value;
}).get();

.map() iterates over the collection and places the return value in a jQuery object.

.get() retrieves an array from a jQuery object.

+10
source
var conferences = [];

$('input:hidden[name^="conf"]').each(function() {
    conferences.push($(this).val());
});
+3
source
var array = $.map($('input:hidden'),function(i) {
    return i.value;
});

array , $(selector).map(), jQuery, get() .

+2
var conferences = new Array();    // object Array

var conferencesVal = new Array(); // string Array

$("[type=hidden]").each(function(i,e){

   // object array  =>altarnatif method
   conferences.push( {name:$(this).attr("id"),value: $(this).val()});

   //string array
   conferencesVal[i]=  $(this).val();

})
+1

.

$(...).attr('value');  

.attr(...): ( html).
.val(): , .

0

, , , #conf1. , conferences[0], conferences[1], ..

, jQuery, , , , , 5 .

0

All Articles