How to gray out HTML form inputs?

Posted by typoknig on Stack Overflow See other posts from Stack Overflow or by typoknig
Published on 2010-06-15T20:12:54Z Indexed on 2010/06/15 21:52 UTC
Read the original article Hit count: 355

Filed under:
|
|
|
|

What is the best way to gray out text inputs on an HTML form? I need the inputs to be grayed out when a user checks a check box. Do I have to use JavaScript for this (not very familiar with JScript) or can I use PHP (which I am more familiar with)?

EDIT:

After some reading I have got a little bit of code, but it is giving me problems. For some reason I cannot get my script to work based on the state of the form input (enabled or disabled) or the state of my checkbox (checked or unchecked), but my script works fine when I base it on the values of the form inputs. I have written my code exactly like several examples online (mainly this one) but to no avail. None of the stuff that is commented out will work. What am I doing wrong here?

            <label>Mailing address same as residental address</label>
        <input name="checkbox" onclick="disable_enable() "type="checkbox" style="width:15px"/><br/><br/>

        <script type="text/javascript">

            function disable_enable(){

                if (document.form.mail_street_address.value==1)
                    document.form.mail_street_address.value=0;
                    //document.form.mail_street_address.disabled=true;
                    //document.form.mail_city.disabled=true;
                    //document.form.mail_state.disabled=true;
                    //document.form.mail_zip.disabled=true;

                else
                    document.form.mail_street_address.value=1;
                    //document.form.mail_street.disabled=false;
                    //document.form.mail_city.disabled=false;
                    //document.form.mail_state.disabled=false;
                    //document.form.mail_zip.disabled=false;

            }

        </script>

© Stack Overflow or respective owner

Related posts about php

Related posts about html