how to access the input tag in the form with jquery? (include the hidden type)

advertisements

I looking for how to access input tag in form via jquery.

I made something like below :

HTML

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>test </title>
<script src="/resources/gtl_portal/js/jquery/jquery-2.1.1.min.js"></script>
<script src="/resources/gtl_portal/js/comon.js"></script>
</head>
<body>
<form id="a" action="#">
    <input type="text" name="name" value=""><br/>
    <input type="text" name="phone" value="numbervalidation"><br/>
    <input type="hidden" name="hiddenParam" value="hidden parameters"><br/>

    <a href="#" onclick="chk()">press</a><br/>
</form>
<script>
    function chk(){
        checkValidation('a');
    }
</script>
</body>
</html>

and in common.js

function checkValidation(formName){
    var form = $('#' + formName);

    form.children('input').each(function(k){
        var obj = $(this);
        console.log(obj.val());
    }
};

I can get value from input tags without hidden type. How can I get hidden type also at once. I found follow article. But if I use this, it looks have to iterate form twice which I do not want to.

Link : jQuery access input hidden value

Is there any way to access hidden and not hidden at once?

Thanks :D

P.S/ I also curious about access multiple selector. I have tried

form.children('input, textarea, select').each(function(i){//do something});

but does not work. Would you find anything wrong from here?


You can use the :input selector. It selects all <input> elements including hidden inputs

$(":input");

Simply selecting the elements by tag name like $("input"); works as well.