Search code examples
jquerydjangoformsappendclone

Form now loads errors in a second form underneath the first


for some reason after having changed my code from this:

<script type="text/javascript">
$(document).ready(function(){

    $("recipebutton1").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").replaceWith($('recipepopup1').css('display','block'));
    });
    $("#recipebutton2").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").replaceWith($('#recipepopup2').css('display','block'));
    });
    $("#recipebutton3").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").replaceWith($('#recipepopup3').css('display','block'));
    });
    $("#recipebutton4").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").replaceWith($('#recipepopup4').css('display','block'));
    });
    $("#recipebutton5").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").replaceWith($('#recipepopup5').css('display','block'));
    });
    $("#recipebutton6").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").replaceWith($('#recipepopup6').css('display','block'));
    });
    $(".create").click(function(){
        $('.recipepopup').css('display', 'none');
        $('#create_form_span').css('display', 'block');
        });
});
</script>   

to this:

<script type="text/javascript">
$(document).ready(function(){
    $("#recipebutton1").click(function(){
        $('#create_form_span').css('display', 'none');
        $(".recipepopup").css('display','none');
        $("#recipe_display").empty();
        $('#recipepopup1').clone().attr('id','clone1').css('display','block').appendTo('#recipe_display'); // append to where you want

    });
    $("#recipebutton2").click(function(){
        $('#create_form_span').css('display', 'none');
        $(".recipepopup").css('display','none');
        $("#recipe_display").empty();
        $('#recipepopup2').clone().attr('id','clone2').css('display','block').appendTo('#recipe_display'); // append to where you want
    });
    $("#recipebutton3").click(function(){
        $('#create_form_span').css('display', 'none');
        $(".recipepopup").css('display','none');
        $("#recipe_display").empty();
        $('#recipepopup3').clone().attr('id','clone3').css('display','block').appendTo('#recipe_display'); // append to where you want
    });
    $("#recipebutton4").click(function(){
        $('#create_form_span').css('display', 'none');
        $(".recipepopup").css('display','none');
        $("#recipe_display").empty();
        $('#recipepopup4').clone().attr('id','clone4').css('display','block').appendTo('#recipe_display'); // append to where you want
    });
    $("#recipebutton5").click(function(){
        $('#create_form_span').css('display', 'none');
        $("#recipe_display").empty();
        $('#recipepopup5').clone().attr('id','clone5').css('display','block').appendTo('#recipe_display'); // append to where you want
    });
    $("#recipebutton6").click(function(){
        $('#create_form_span').css('display', 'none');
        $(".recipepopup").css('display','none');
        $("#recipe_display").empty();
        $('#recipepopup6').clone().attr('id','clone6').css('display','block').appendTo('#recipe_display'); // append to where you want
    });
    $(".create").click(function(){
        $("#recipe_display").empty();
        $('#create_form_span').css('display', 'block');
        });
});
</script>   

has made it so my form now just continuously loads a new form under the current one

can anyone think of any reason why something like this might be happening? its driving me absolutely insane!

katie


Solution

  • i dont know what was causing the form to continuously load beneath itself but i was able to solve the problem by loading the html into the div instead of appending/replaceWith

    this worked very well and I am glad i now know how to use jquerys .html feature