Ruble Gomes
Ruble Gomes

Reputation: 117

jQuery Ligthbox open and close instantly

I have a function to erase some commerce from the database, I want the confirmation to appeared in a lightbox. It does open in a lightbox but it close almost instantly =/

jQuery:

    $('a#MontrerSuppression').click(function(){

    $('#BackgroundSuppression,#Suppression').fadeIn('fast');

});

$('a#CacherSuppression').click(function(){

    $('#BackgroundSuppression,#Suppression').fadeOut('fast');

});

php/html:

<a href='myaccount.php?IDCommerce=<?php echo $Commerce['IDCommerce'];?>' id="MontrerSuppression">Supprimer Commerce</a>

css:

BackgroundSuppression{width: 100%; height: 100%; position: absolute; top:0; left: 0; background-color: #999; opacity: 0.5; z-index: 1; display: none;}

Suppression{position: absolute; width: 375px; background: #fff; border: 1px solid #000; padding: 20px 20px 10px 10px; top: 50%; margin-top: -130px; left:50%; margin-left: -250px; z-index: 2; display: none; text-align: center;}

The form:

            <div id="Suppression">
            <a href="#" id="CacherSuppression"><strong>×</strong></a>

            <?php supprimerCommerce(); ?>

            <form method="POST" action="myaccount.php">
                <p>Êtes vous sur de vouloir supprimer votre commerce?</br>Une fois supprimer les informations seront perdu à jamais.</p>
                <input type="submit" name="Confirmer" value="Oui"/>
                <input type="submit" name="Annuler" value="Annuler"/>
            </form>
        </div>

Think the problem is on the way I "link" the html link to the jQuery function but can't figure out what is the proper way to do it.

Really appreciat if someone could give me some help

Upvotes: 2

Views: 230

Answers (2)

Jithin
Jithin

Reputation: 2604

I hope for a#MontrerSuppression contains an href attribute. So to remove its from clicked try the following.

$('a#MontrerSuppression').click(function(event){
    event.preventDefault();
    $('#BackgroundSuppression,#Suppression').fadeIn('fast');
});

Upvotes: 0

sdespont
sdespont

Reputation: 14025

Try this fiddle and let me know if it is OK for you

EDIT

OK, I understand. The fact is that the onclick event is overwrited by the href link. Try this fiddle version : http://jsfiddle.net/dMpNE/1/

Upvotes: 0

Related Questions