Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get hidden field value Jquery?

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 am trying to get the values of the hidden fields in to an array using jquery. Here is what i have 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 anyone direct me on how to read them?
Thanks in Advance
Dean

like image 988
Dean Avatar asked Jul 06 '10 21:07

Dean


People also ask

How can store hidden field value in jQuery?

In jQuery to set a hidden field value, we use . val() method. The jQuery . val() method is used to get or set the values of form elements such as input, select, textarea.

How can check hidden field value is null or not in jQuery?

You can use exclamation mark ! to check if it is null.

How check element is hidden or not in jQuery?

To check if an element is hidden or not, jQuery :hidden selector can be used. .toggle() function is used to toggle the visibility of an element.


1 Answers

If you're 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 into a jQuery object.

.get() retrieves the array from the jQuery object.

  • http://api.jquery.com/map/
  • http://api.jquery.com/get/
like image 86
user113716 Avatar answered Sep 27 '22 22:09

user113716