Jump to content

Help with HTML form


DarkHorizon

Recommended Posts

Hi,
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?

cheers
DH
Link to comment
Share on other sites

try this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
function checksub(obj)
{
if(obj.checked==true)
{
document.frmtest.txt_once.disabled=true;
}
else
{
document.frmtest.txt_once.disabled=false;
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM name='frmtest' METHOD=POST ACTION="" >
<INPUT TYPE="checkbox" NAME="chk_once" onclick="return checksub(this);">checkbox <INPUT TYPE="text" NAME="txt_once">
</FORM>
</BODY>
</HTML>
Link to comment
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">
<head>
<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;
    }
}

</script>

</head>
<body>

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

</body>
</html>[/code]
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.