Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
How do I create another function to remove the appended form?
<script type="text/javascript">
  i=1; 
  function cloneDFLStep(){
    i++;
    
    var appendThis = '<hr><div id="formId" class="form-group"><label for="fa_title">Step '+i+'</label><input type="text" class="form-control" id="fa_title[]" name="fa_title[]"  placeholder="Enter Step Title ['+i+']"><br><textarea class="form-control" id="f_steps" name="f_steps[]" placeholder="Steps Description (Include All Steps Taken On Analysis) ['+i+']" rows="5"></textarea><br><textarea class="form-control" id="s_remarks" name="s_remarks[]" placeholder="Remarks (Add Any Remarks On Steps Taken) ['+i+']" rows="3"></textarea><hr><input class="minusbtn btn btn-sm btn-warning" type="button" name="removef" value="Delete Step ['+i+']"></div>';
    $('.appendRow').append(appendThis);

  }

</script>

This code appends a new form anytime the button is clicked. How Do I create a function to remove the new appended forms with the button created?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

  1. Wrap the string you stored in appendThis with $(), so you have an jQuery set of (not rendered) elements which you can operate on.

  2. Bind a click event to the minusbtn class of your created delete button

  3. Delete all previously rendered elements (=> stored in appendThis) inside the click event.

See this Fiddle: https://jsfiddle.net/z9d8nphm/

Extended Code:

<script type="text/javascript">
  i=1; 
  function cloneDFLStep(){
    i++;
    
    // ATTENTION. STRING WRAPPED HERE: var $appendThis = $(...) 
    var $appendThis = $('<hr><div id="formId" class="form-group"><label for="fa_title">Step '+i+'</label><input type="text" class="form-control" id="fa_title[]" name="fa_title[]"  placeholder="Enter Step Title ['+i+']"><br><textarea class="form-control" id="f_steps" name="f_steps[]" placeholder="Steps Description (Include All Steps Taken On Analysis) ['+i+']" rows="5"></textarea><br><textarea class="form-control" id="s_remarks" name="s_remarks[]" placeholder="Remarks (Add Any Remarks On Steps Taken) ['+i+']" rows="3"></textarea><hr><input class="minusbtn btn btn-sm btn-warning" type="button" name="removef" value="Delete Step ['+i+']"></div>' );

    $appendThis.find( '.minusbtn' ).click( function( event ) {

        event.preventDefault();

        $appendThis.remove();
    });

    $('.appendRow').append($appendThis);
  }

</script>
about 4 years ago · Juan Pablo Isaza Denunciar

0

<div class="appendRow"></div>

<button onclick="cloneDFLStep()">cloneDFLStep</button>

<script type="text/javascript">
  i=1; 
  function cloneDFLStep(){
    i++;
    
    var $appendThis = $('<hr><div id="formId" class="form-group"><label for="fa_title">Step '+i+'</label><input type="text" class="form-control" id="fa_title[]" name="fa_title[]"  placeholder="Enter Step Title ['+i+']"><br><textarea class="form-control" id="f_steps" name="f_steps[]" placeholder="Steps Description (Include All Steps Taken On Analysis) ['+i+']" rows="5"></textarea><br><textarea class="form-control" id="s_remarks" name="s_remarks[]" placeholder="Remarks (Add Any Remarks On Steps Taken) ['+i+']" rows="3"></textarea><hr><input class="btn btn-sm btn-warning" id="removeForm" type="button" name="removef" value="Delete Step ['+i+']"></div>' );
    $appendThis.children( '#removeForm' ).click(function(){ 
   $appendThis.remove();
  })
    $('.appendRow').append($appendThis);

  }

</script>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda