Clear the value if unchecked the checkbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vyon13
    New Member
    • Feb 2008
    • 8

    Clear the value if unchecked the checkbox

    this is the code that i have copy:i tried to add new function on it,... the function is if the checkbox is unchecked the value inputed by the user will be clear... how to do that..

    thanks in advance!!!


    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
    <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    // by Vic Phillips http://www.vicsjavascripts.org.uk/
    
    function Disable(obj,state){
    	clds=obj.parentNode.childNodes;
    	if (!obj.ary){
    	obj.ary=new Array();
    		for (i1=0;i1<clds.length;i1++){
    			if (clds[i1].tagName=='INPUT'){
    				obj.ary[obj.ary.length]=clds[i1];
    				}
    		}
    	}
    	for (i=0;i<obj.ary.length;i++){
    		obj.ary[i].removeAttribute('disabled');
    	}
    	if (obj.checked==state){
    		for (i1=0;i1<obj.ary.length;i1++){
    			obj.ary[i1].setAttribute('disabled','disabled');
    		}
    	}
    	obj.removeAttribute('disabled');
    
    }
    
    //-->
    </script>
    
    </head>
    
    <body>
    <span>
    <input type="checkbox" name="" onclick="Disable(this,false);" >
    <input type="text" name="" disabled="disabled" >
    <input type="text" name="" disabled="disabled" >
    <input type="text" name="" disabled="disabled" >
    </span><br />
    
    
    </body>
    
    </html>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    [code=javascript]//To clear a textbox
    textbox.value = ""; // where textbox is a reference to the textbox
    To check if checkbox is unchecked
    if (!obj.checked) { ...[/code]

    Comment

    Working...