Jump to content

[SOLVED] Using a checkbox to enabled/disabled a text field?


Presto-X

Recommended Posts

Hello Guys I'm trying to use a checkbox to enabled/disabled a text field. Can any one offer some advice?

 

This is the code I'm trying to use but it does not work :(

<script type="text/javascript">
function calldate(){
if (document.forms['services'].calcheckbox.checked==true){
document.forms['services'].calldate.disabled=false;
}
}
</script>
<input name="calldate" type="text" disabled="true" value="<?php echo "$calldate"; ?>"> 
<label><input name="calcheckbox" onclick="calldate()" type="checkbox" /> Change Date</label>

<script language="javascript">
function set(checkobj){
	if(checkobj.checked){
		document.getElementById('textb').disabled = true;
		//document.getElementById('textb').style.display = "none";
	}else{
		document.getElementById('textb').disabled = false;
		//document.getElementById('textb').style.display = "";
	}
}
</script>
<input type="checkbox" name="check" id="check" onclick="javascript:set(this)"/>
<input type="text" name="textb" id="textb"/>

Hey schme16 I'm using this code with php and php in inbeded in this code so :OP

 

Hey Jitesh thanks for the help, I ended up changing to look like this and it worked great! thanks...

<script language="javascript">
function set(checkobj){
	if(checkobj.checked){
		document.getElementById('calldate').disabled = false;
		//document.getElementById('calldate').style.display = "";
	}else{
		document.getElementById('calldate').disabled = true;
		//document.getElementById('calldate').style.display = "none";
	}
}
</script>
<input type="text" name="calldate" id="calldate" disabled="true" value="<?php echo "$calldate"; ?>"/><input type="checkbox" name="check" id="check" onclick="javascript:set(this)"/>

Thats kool, just thoguht i'd mention it is all, and like i said, far be it my place to say anything in the first place...i'm usualy the one posting out of place ( mostly due to have a million tabs open at once!)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.