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

How do i clear textBox contents when checkBox is unchecked

P: 1
Expand|Select|Wrap|Line Numbers
  1. function getCurrentDateString(checkBox, inputName){
  2.     if(checkBox.checked == true){
  3.         var inputBox = eval("document.PortfolioInquiryChange."+inputName);
  4.         if(inputBox.value==""){
  5.             var dateobj= new Date();
  6.              var month = dateobj.getMonth();
  7.              var day = dateobj.getDate();
  8.              var year = dateobj.getFullYear();
  9.             inputBox.value= day + "/" + month + "/" + year;
  10.         }
  11.  
  12.     }
  13.     else{ 
  14.         inputBox.clear();
  15.     }
  16.  
  17. }
Apr 16 '14 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
you simply set the value to an empty string (there is no clear() method on form fields). you may also call the reset() method of the form, although that will reset all form elements.

PS. donít use eval() on line #3, bracket notation will do.
Apr 16 '14 #2

Post your reply

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