SQL PHP HTML ASP JavaScript articles and free scripts to download

Enable and disable of text box through a checkbox

We may need to enable or disable a text box based on the input of the user by using disabled property of the element. For example we have some choices for the visitor and one of the options is Others. Once the visitor select the others options then ( only ) one text box will be enabled to allow the visitor to fill the details.

Demo of Enable Disable text box

We have used the body onload command to keep the text area disabled while the page is loading.

The full code is here.

<html>
<head>
<title>(Type a title for your page here)</title>
<script language="JavaScript">
<!--

function enable_text(status)
{
status=!status;
document.f1.other_text.disabled = status;
}
//-->
</script>
</head>
<body onload=enable_text(false);>

<form name=f1 method=post>
<input type="checkbox" name=others onclick="enable_text(this.checked)" >Others
<input type=text name=other_text>
</form>

</body>
</html>


Google+

More on CheckBox & PHP
Sumith Harshan07-01-2011
I found everywhere this one.finally i found this by in this site.very simple and useful.good job.thank you.good luck.
Chris03-06-2012
This works as described, but what if I want to have multiple disabled text fields linked to multiple checkboxes? The result for me is that checking ONE box enables ALL the text fields, but I would like it to only enable the one. Any ideas? Thanks!
newbie02-08-2012
this was helpful for me! thank you bro..
Merline05-04-2013
This Works.. Really superb..
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Form Validation in JavaScript
Checkbox Validation of a form



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer