0

I want to open an empty form when i will click on the Create A New Account button. I used javascript here so that after uploading a resume, it will automatically pop up registration page with name and emailid. But if i close the form and again press on create a new account it is not opening an empty form but with data.

I have my button on

base.html

          <div class="forgot_create-new">
             <a href="#" class="upload_btn_resume up_res">Upload Resume</a>
             <a href="#" class="new_account">Create New Account?</a>
          </div>

And i have my form on

index.html

<form id="ApplicantFormRegister" name="ApplicantFormRegister" class="form-horizontal 
      ApplicantForm" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label class="col-sm-4 control-label">Email ID<span class="important">*</span></label>...........cont

I tried below but unable to open an empty form

$('#form_id').trigger("reset");
  • Does this answer your question? [How to reset a form using jQuery with .reset() method](https://stackoverflow.com/questions/16452699/how-to-reset-a-form-using-jquery-with-reset-method) OR this one => https://stackoverflow.com/questions/680241/resetting-a-multi-stage-form-with-jquery – Always Helping Sep 28 '20 at 08:23
  • You don't have a `reset` event listener set. Try with the native `reset` method: `$('#form_id')[0].reset();`. – Teemu Sep 28 '20 at 08:23
  • @AlwaysHelping I tried those – Manas Ranjan Pati Sep 28 '20 at 08:28

2 Answers2

0

Just use createElement() to create it...

var F=document.createElement('form');

F.id='ApplicantFormRegister'; 

F.name='ApplicantFormRegister';

F.class='form-horizontal ApplicantForm';

F.method='POST';

F.enctype='multipart/form-data';

document.body.appendChild(F);

And then add any fields/elements you want to it like this...

ApplicantFormRegister.innerHTML+='<div>Hello</div>';

NB: I’m not sure what you mean by “open a form” because once a form is already declared then there’s nothing to open… it’s always there and you just hide/unhide it as required. That’s why I assumed that “open” means "create".

0

I tried following and it worked

$('.new_account').click(function(e){
    e.preventDefault();
    $('#login_register').modal('show');
    $('#register_div').show()
    #formid
    $('#ApplicantFormRegister').get(0).reset()