Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get all input types with name, id, value in JQuery

Tags:

jquery

In JQuery, how can i get list of input type with name, id and value present in any div?

like image 727
Pradip Avatar asked Aug 16 '12 08:08

Pradip


3 Answers

Selects inputs that descend from a div that have both name, id, and value attributes present. Then pushes the "type" attribute of each matching item into an array.

var inputTypes = [];

$('div input[name][id][value]').each(function(){
     inputTypes.push($(this).attr('type'));
});

http://api.jquery.com/multiple-attribute-selector/

like image 113
HandiworkNYC.com Avatar answered Oct 21 '22 05:10

HandiworkNYC.com


In JQuery, how can i get list of input type...

This?

var inputTypes = [];
$('input[name!=""][value!=""][id!=""]').each(function() {
    inputTypes.push($(this).prop('type'));
});

The property!="" is necessary than just [property], this is to filter out things like

<input type="text" name="something" value="" id="someId" />

(Which I assume you don't want to get input with any property equals to empty string)

like image 33
Andreas Wong Avatar answered Oct 21 '22 03:10

Andreas Wong


You can look at each input, get their attributes and check against an empty string for each. You could use any method you want to present them, here I'm just adding them to an array.

var inputs = new Array();  

$("input").each(function() {
    var name = $(this).attr("name");
    var id = $(this).attr("id");
    var val = $(this).val();

    if ((name) && name !== "") && ((id) && id !== "") && ((val) && val !== "")) {
        inputs.push(this);
    }
});
like image 40
Paul Aldred-Bann Avatar answered Oct 21 '22 03:10

Paul Aldred-Bann