0

How do i get a javascript code to only execute or be used once? example is

var stringToMatch = 'christopher';
function toggle (){   

 var input = document.getElementById('text').value; 

 if (input == stringToMatch){  
    document.getElementById('divColor1').style.display = 'block';   
}   
else {   
   document.getElementById('divColor1').style.display = 'none';   
}   
} 

this code or stringToMatch i want to execute once, after that i dont care if it is deleted in the sense. for this is for coupons. and i am making multiples of this, so once someone has typed this i want it to delete

1
  • let me better phrase now that i see adding two of these only makes the second one work. i want to make we will say 100 coupon codes. 'christopher' being the example used here. once someone hits redeem it takes 'christopher' out of the coupons list. and the others are still there. is this possible? Commented Aug 2, 2012 at 6:23

1 Answer 1

1

If I got you right, you could overwrite toggle() with an empty function.

if (input == stringToMatch){  
    document.getElementById('divColor1').style.display = 'block';   
    window.toggle = function() { };
}
Sign up to request clarification or add additional context in comments.

2 Comments

i dont understand this sorry. I also tried a switch a switch (stringToMatch) { case 0: x="Today it's Sunday"; break; case 1: x="Today it's Monday"; break; case 2: x="Today it's Tuesday"; break; case 3: x="Today it's Wednesday"; break; case 4: x="Today it's Thursday"; break; case 5: x="Today it's Friday"; break; case 6: x="Today it's Saturday"; break; to try and change the coupon "name" to more than just one. which it did not work. basically I want once 'christopher' is used its deleted. then if any of the others used they
as well. I know this is a burden and im probably a hassel lol. Im just tryin to get this code to work the way i need it to

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.