Results 1 to 3 of 3

Thread: Disable Text Box with CSS Style

  1. #1
    Join Date
    Apr 2006
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Disable Text Box with CSS Style

    I'm trying to develop the code below. I'd like to control the textbox styll using CSS when the text box is disabled and enabled.

    Here is a link to see what I'm looking to do:
    http://charity-funding.us/groupRes/disableTest.html

    As you can see, when the radioBTN for MasterContract is selected the textBoxes are disabled. Any of the other three radioBTNs enables the textBoxes.

    I've added a style to two textboxes as an example. The style is active when the box is enabled or disabled. I'd like to create a NEW style specific to the DISABLED box when the MasterContract radio is SELECTED. Can anyone help with this please? THANKS!!!

    Here is the code below...

    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    
    
    <script language="javascript">
    
    function enableField()
    {
    document.form1.address2.disabled=false;
    document.form1.address22.disabled=false;
    document.form1.address23.disabled=false;
    document.form1.address24.disabled=false;
    }
    
    function disableField()
    {
    document.form1.address2.disabled=true;
    document.form1.address22.disabled=true;
    document.form1.address23.disabled=true;
    document.form1.address24.disabled=true;
    }
    
     
    </script>
    
    
    <style type="text/css">
    <!--
    body {
    	background-color: #FFFFFF;
    }
    .inputext {
        font-family: Arial, Helvetica, sans-serif;
    	font-size: 12px;
    	font-weight: normal;
    	color: #243E5F;
    	width: 170px;
    	border: 1px solid #afbadd;
    	background-image: url(http://www.charity-funding.us/groupRes/images/pagebuild/txtBoxBG.gif);
    	background-repeat: repeat-x;
    	margin-top: 2px;
    	margin-bottom: 5px;
    	height: 22px;
    	background-color: white ! important;
    	z-index: 1000;	
    }
    -->
    </style>
    </head>
    
    <body onload="disableField()">
    <form name="form1" >
      <p>
      <input name="address2" type="text" disabled="true"  id="address2" />
      <input name="address22" type="text" disabled="true" class="inputext" id="address22" />
      <input name="address23" type="text" disabled="true"  id="address23" />
        <input name="address24" type="text" disabled="true" class="inputext" id="address24" />
        
    </p>
      <p>
        <input name="radiobutton" type="radio" value="radiobutton" onfocus="enableField()"/>
        <span class="txtBlue">
        <html:radio property="payType" value="<%=hotel.model.property.Rate.PREPAY%>">Pre-Pay To Merchant Account</html:radio>
      </span>
        <input name="radiobutton" type="radio" value="radiobutton" onfocus="enableField()" />
      Pay Upon Checkout  
      <input name="radiobutton" type="radio" value="radiobutton" onfocus="enableField()"/>
      Pre-Pay To Hotel   
      <input name="radiobutton" type="radio" onfocus="disableField()" value="test" checked="checked" />
      Master Contract  </p>
    </form>
    
    </body>
    </html>

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    You can't. But you can hide it.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The best way of "disabling" a text box with CSS is to put a transparent element over the top of it so it can't receive focus. It will also be necessary to prevent keyboard navigation.

    Of course, this is an ugly hack. Just set .disabled in your script.
    Code:
    <script language="javascript">
    language is deprecated;
    type is required.
    Code:
    document.form1.address2.disabled=false;
    document.form1.address22.disabled=false;
    document.form1.address23.disabled=false;
    document.form1.address24.disabled=false;
    Try:
    Code:
    var f = document.forms.form1.elements;
    for(var i = 0; i < f.length; ++i)
      f['address2' + (i || '')].disabled=false;
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •