0

I have multiple form elements on a page and I have a next button for each form. I fill a form and click on next button to scroll to next form. I want that after filling up a form when user clicks next button it should disable all elements of previous elements.

What I tried:
I assigned unique id to all forms and tried following

$('form #firstFrm').find('input').attr('disabled','disabled');

But it did not do anyything.

$("#firstFrm> input").attr("disabled", true);

but not effect.

$("#firstFrm :input").attr("disabled", true);

for this instead of disabling elements under form with id firstFrm it disable elements of all form.

how to disable elements of particular form only.

HTML Code

<form action="" method="post">      
    <fieldset class="sectionwrap">
        <legend style="padding-right: 425px;">User Details</legend>
        <fieldset class="column" style= "width: 500px;margin-top: 10px;">
            <div id="firstFrm">
                <table style="padding-right: 20px; float: left"> 
                    <tr>
                        <td id="targetTD">
                            Username : <input id="email" type="email" name="email"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Password : <input id="password" name="password" type="password" class="text" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            password : <input id="confirmPassword" name="confirmPassword" type="password" class="text" />
                        </td>
                    </tr>
                </table>
            </div>
        </fieldset>

    </fieldset>
</form>

Solution

I created div under form and put all elements in that div and instead of disabling elements under form I disabled elements under div. This worked fine.

Sandeep Kumar
  • 13,799
  • 21
  • 74
  • 110

3 Answers3

0

Try with this:

$( '#firstFrm input' ).attr ( 'disabled', true );
Jan Hančič
  • 53,269
  • 16
  • 95
  • 99
0

This would be a bit lenghty but you can try that as soon as the user goes to next input type you can disable the above elment using its id i.e.

{ $( '#input' ).attr ( 'disabled', true ); }
Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105
Engineer
  • 5,911
  • 4
  • 31
  • 58
0

$('form #firstFrm') will look for a form with id="firstForm" which is inside another <form> element

<form>
    <div>
        <form id="firstForm"></form>
    </div>
</form>

$("#firstFrm > input") will get only the direct <input/> children of a form

<form>
    <input />     // this is matched
    <div>
        <input/>  // this is not matched
    </div>
</form>

To get all the inputs try this:

$("input", $("#formId")).attr("disabled", true)

or

$("#formId input").attr("disabled", true)
Catalin
  • 11,503
  • 19
  • 74
  • 147