Jump to content

On Checkbox, Disable Field.


phpSensei

Recommended Posts

I have a form where user's can upload an image. You can chose to input the width, height of the image yourself, but I want a checkbox when its check that those two fields are disabled.

 

Checkbox= Resize Automatically

 

Width=

height=

 

So If the check box is not checked, you can type in the two width and height fields, but when it is checked, they become disabled.

 

hope you understand..

 

Link to comment
https://forums.phpfreaks.com/topic/65123-on-checkbox-disable-field/
Share on other sites

<script type="text/javascript">
function toggle_size_fields()
{
height_obj = document.getElementById('height')
width_obj = document.getElementById('width')

if(height_obj.disabled == true)
{
	height_obj.disabled = false
}
else {
	height_obj.disabled = true
}

if(width_obj.disabled == true)
{
	width_obj.disabled = false
}
else {
	width_obj.disabled = true
}
}
</script>

<form>
<label><input type='checkbox' name='resize_auto' onclick='toggle_size_fields()' /> Resize automatically?</label><br />
<label>Width: <input type='text' name='width' id='width' /><br />
<label>Height: <input type='text' name='height' id='height' /><br />
</form>

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.