Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > HTML > HTML Code Clinic
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 20th, 2006, 12:37 PM
Registered User
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to pollockc
Default disable input elements without using "disabled"

I'm creating a form that the user will print off. When I use the input "disabled" property the boxes become greyed and are very difficult to see when printed out.
However, I don't want the user to be able to change the input (and select) form elements on the print page.
I'm assuming there has to be a javascript way of disabling the input and select elements without actually using the "disabled" property.
Your help would be greatly appreciated!

:: Chris Pollock ::
 
Old January 20th, 2006, 12:40 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Chris,

You can use the readonly property to do this.

HTH,

Chris

 
Old January 20th, 2006, 12:48 PM
Registered User
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to pollockc
Default

I should have been more specific. Really I need to disable radio buttons, checkboxes, and select elements. "readonly" works only with "text".

:: Chris Pollock ::
 
Old January 23rd, 2006, 06:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

You could create a Javascript function like the following :

var isRO=true;
function isFieldRO(this)
{
    if (isRO)
    {
        this.blur();
    }
}
<input type=checkbox onfocus="isFieldRO(this)">
 
Old January 24th, 2006, 10:44 AM
Registered User
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to pollockc
Default

Quote:
quote:Originally posted by Greg Griffiths
 You could create a Javascript function like the following :

var isRO=true;
function isFieldRO(this)
{
    if (isRO)
    {
        this.blur();
    }
}
<input type=checkbox onfocus="isFieldRO(this)">
Hmmm.. this didn't work either. The Javascript is not "bombing", but it doesn't seem to be disallowing the input. I'm mystified! I think I"m going to try and build a page with nothing else on it and see if it works, but right now all of the suggested options don't seem to do the job.

I do thank you for taking the time to write thought.
Any other ideas out there

:: Chris Pollock ::
 
Old January 24th, 2006, 10:51 AM
Registered User
 
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to pollockc
Default

OK!!!
I figured it out. I needed to include another operation, besides the blur in order for it to work. Here's what I did:

Code:
<script language="javascript">
var isRO=true;
function isFieldRO(myelement) {
if(isRO){
myelement.blur();
alert('Sorry, you cannot change this element.');
}
}
</script>
I bolded the change that I made. I'm not sure why this is, but it works. Thank you everyone for your help!!

:: Chris Pollock ::





Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable View>Source (disable html source) kazmughal44 HTML Code Clinic 11 December 11th, 2007 11:53 AM
Enable/Disable Form Elements Question kwilliams Javascript 4 February 28th, 2006 11:28 AM
Disable/Enable elements ldoodle Javascript How-To 3 June 7th, 2005 05:48 AM
Disable Form Elements Hotwax ASP.NET 1.0 and 1.1 Professional 2 October 31st, 2003 08:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.