Disable a textfield when a checkbox is checked

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Disable a textfield when a checkbox is checked

Post by tores »

Hi

Is it possible to have a html text field disabled if or if not a checkbox is checked, without having to submit a post and reload the whole page? If it's possible I would like to know how.

tores
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

You could use javascript.

Code: Select all

<input type="checkbox"  name="is_new" value="1" onclick="
bVal=!this.checked;
topic_name.disabled=bVal;
if(!bVal)topic_name.focus()
" checked>

<input type="text" name="topic_name">
Post Reply