J'essaye de mettre en place un script simple pour basculer un lien d'une case à cocher.Un script javascript simple a mal tourné!
Le script que j'ai ci-dessous fonctionne, mais il ne modifie que le href de la première instance.
Je suis sûr qu'il y a probablement une façon beaucoup plus simple de faire cela, car j'ai beaucoup de code redondant.
Quelqu'un peut-il aider à faire la lumière sur ce sujet pour moi?
Merci! Nick
<script type="text/javascript">
function toggleLinks() {
//instant attraction
if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C1") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C15";
else if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C15") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C1";
//fashion bible
if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C4") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C16";
else if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C16") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C4";
//underground dating seminar
if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C5") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C17";
else if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C17") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C5";
//planning the perfect date
if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C6") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C18";
else if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C18") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C6";
//how to beat approach anxiety
if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C7") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C19";
else if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C19") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C7";
//interviews with naturals
if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C8") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C20";
else if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C20") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C8";
//crocodile style
if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C9") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C21";
else if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C21") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C9";
//pheromone kids 10 minute seduction
if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C10") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C22";
else if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C22") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C10";
//joe natural uncensored
if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C11") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C23";
else if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C23") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C11";
//buzzy: master of threesomes
if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C12") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C24";
else if (document.getElementById('add_to_cart').href == "http://bradp.com/dlg/sell.php?prodData=cb%2C24") document.getElementById('add_to_cart').href = "http://bradp.com/dlg/sell.php?prodData=cb%2C12";
}
</script>
Un autre conseil, vous ne pouvez avoir qu'un tag avec un ID donné. – Cleiton