DarkHorizon Posted August 3, 2006 Share Posted August 3, 2006 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?cheersDH Quote Link to comment https://forums.phpfreaks.com/topic/16432-help-with-html-form/ Share on other sites More sharing options...
manmadareddy Posted August 3, 2006 Share Posted August 3, 2006 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> Quote Link to comment https://forums.phpfreaks.com/topic/16432-help-with-html-form/#findComment-68433 Share on other sites More sharing options...
wildteen88 Posted August 3, 2006 Share Posted August 3, 2006 [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 changedfunction 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] Quote Link to comment https://forums.phpfreaks.com/topic/16432-help-with-html-form/#findComment-68436 Share on other sites More sharing options...
DarkHorizon Posted August 3, 2006 Author Share Posted August 3, 2006 many thanks guysi 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 Quote Link to comment https://forums.phpfreaks.com/topic/16432-help-with-html-form/#findComment-68448 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.