By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,400 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,400 IT Pros & Developers. It's quick & easy.

clearing onlclick event

P: 1
Hi there, I used the following 2 functions to change the text on a button and open a hidden div at the same. I want to revert back to the original text on the button (read more..) when I click to close the div again.

Please help :D

Expand|Select|Wrap|Line Numbers
  1. function onclick(){
  2.     javascript:readmore('text1')
  3. }
  4.  
  5. function valChange(){
  6.     document.myForm.myButton.value="...reduce text"
  7. }
  8.  
May 19 '11 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
make a new function that restores the original Text and interchange the two handlers each time the button is pressed.

ex.
Expand|Select|Wrap|Line Numbers
  1. function changeVal()
  2. {
  3.     this.value = " reduce text";
  4.     this.removeEventListener("click", changeVal, false);
  5.     this.addEventListener("click", changeValBack, false);
  6. }
  7. function changeValBack()
  8. {
  9.     this.value = " read more";
  10.     this.removeEventListener("click", changeValBack, false);
  11.     this.addEventListener("click", changeVal, false);
  12. }
  13. // button is the reference to the button element
  14. button.addEventListener("click", changeVal, false);
May 19 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.