SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript to gray out a textbox when a checkbox is marked?

    Does anyone know of a script that will make a textbox so it can't be typed in once the corresponding checkbox is marked? (there are multipe on the same page)
    John Saunders

  2. #2
    AdSpeed.com Son Nguyen's Avatar
    Join Date
    Aug 2000
    Location
    Silicon Valley
    Posts
    2,241
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The basic idea is: document.myForm.myField.disabled = true;

    If there are multiple, make sure their names are different.
    - Son Nguyen
    AdSpeed.com - Ad Serving and Ad Management Made Easy

  3. #3
    I ♥ PHP
    Join Date
    Jul 2003
    Location
    Melbourne, Australia
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi John, does this do what you need?

    http://sandbox.windebank.com.au/DisableTextBox

    Regards,
    Jordan

  4. #4
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to grey out, u can use the above one:
    document.myForm.myField.disabled = true;

    if you want to show as normal one and want to restrict the user to add text:
    document.myForm.myField.readOnly = true;

    hope this helps..!

    thnx,
    krishna

  5. #5
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help. I'm using this code but for some reason when I click the box, CLOSED shows up in the textbox and makes it uneditable, but it isn't inserting 'CLOSED' into the database. Whenever I enter text in the box it's saved.

    Code:
    function disableTextbox(checkbox, textbox) {
    	var txt = document.getElementById(textbox);
    	var chk = document.getElementById(checkbox);
    
    	if (chk.checked == true) {
    		txt.value = 'CLOSED';
    		txt.disabled = true;
    	} else if (chk.checked == false) {
    		txt.disabled = false;
    	}
    }
    Any ideas?
    John Saunders


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
  •