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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.