Jump to content


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


Help with HTML form

Recommended Posts

i dont know if this can be done but here goes:

i have a form with two inputs. One is a checkbox and one is a text field.
If the check box is checked, the text field gets greyed-out, disallowing user input to that field.

If the check box is [i]not[/i] checked then the user can fill in the text field instead.

is this possible with a bit of javascript?


Share this post

Link to post
Share on other sites
try this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
function checksub(obj)
<FORM name='frmtest' METHOD=POST ACTION="" >
<INPUT TYPE="checkbox" NAME="chk_once" onclick="return checksub(this);">checkbox <INPUT TYPE="text" NAME="txt_once">

Share this post

Link to post
Share on other sites
[b]Umm, took too long. heheh, ohwell[/b]

This is possible with javascript:
[code]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title>Javascript Test</title>

<script type="text/javascript">

// this function is called evertime the checkbox is changed
function disableBox(box)
    // get checkBox status
    var checkBox = document.form1.chkbox.checked;

    // get form to disable:
    var box2Disable = document.getElementById(box);

    // if checkbox is checked
    if( checkBox == true) {
        // disable the input field
        box2Disable.disabled = true;
    } else {
        // enable the box
        box2Disable.disabled = false;



<form name="form1">
Checkbox: <input type="checkbox" name="chkbox" onclick="disableBox('box1')" /><br />
Box: <input type="text" id="box1" />


Share this post

Link to post
Share on other sites
many thanks guys

i worked through manmadareddy's example first and modified it for 2 seperate check boxes and 18 inputs..

works perfectly.

i have a few more questions...post them soon...cheers DH

Share this post

Link to post
Share on other sites


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.