Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looping through Form fields and show all the form fields except hidden field in that form

Tags:

jquery

Can any one provide me an example to loop through all the form fields and to show those fields except hidden fields in that form.

Pseudo code:

for(i=0;i<formFields.length;i++)
{
if(formFields[i]!= 'hidden field')
then formFields[i].show();
}
like image 575
user3742125 Avatar asked Nov 09 '22 10:11

user3742125


1 Answers

You could try looping through the fields with the following code; however, if the fields have a hidden attribute they will be hidden. No need to apply .show to elements that will already be displayed.

Loop through all visibile fields:

$("#Form1 :input").not(':button, :hidden').each(function() {
    // do whatever with the fields here
});

Update

// show form, clear hidden values
$(".dropdown").on('change', function() {
    if ($(this).val() == "Show all fields") {
        $("#Form1").show();
        $("#Form1 :input").is(':hidden').each(function() {
            $(this).val('');
        });
    }
});

Update 2:

$(".dropdown").on('change', function() { 
    if ($(this).val() == "Show all fields") {
        $("#Form1").show();
        $('#Form1 *').filter(':input').each(function() {(...)});
    }
});
like image 184
NightOwlPrgmr Avatar answered Nov 15 '22 04:11

NightOwlPrgmr