Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-13-2002, 10:28 AM   PM User | #1
scripter
New to the CF scene

 
Join Date: Nov 2002
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
scripter is an unknown quantity at this point
disabling radio buttons and checkboxes in netscape

Hi,

I would like to disable radio buttons and checkboxes in a page.

disabled="true" works only in IE. I want somehting similiar to that for Netscape. Any work around will do which will disable the radio buttons and checkbox.

Thanx in advance
scripter is offline   Reply With Quote
Old 11-13-2002, 04:48 PM   PM User | #2
Roy Sinclair
Senior Coder

 
Join Date: Jun 2002
Location: Wichita
Posts: 3,880
Thanks: 0
Thanked 0 Times in 0 Posts
Roy Sinclair will become famous soon enough
This sample page should get you started:

BTW, you should say NS4 when you mean that decrepit antique that is Netscape 4. Saying just NS would refer to the current version of Netscape which does support the disabled property for form fields.

Code:
<html>
	<head>
		<script>
			function disableField(myField)
				{
				myField.disabled = true
				return true
				}
			function enableField(myField)
				{
				myField.disabled = false
				return true
				}
			function onfocusField(myField)
				{
				if (myField.disabled) 
					{
					myField.blur()
					return false
					}
				return true;
				}
			// The above functions are generic, the following function is specific to this page	
			function toggleFields(myField)
				{
				if (myField.checked)
					{
					disableField(document.forms["example1"].text1)
					disableField(document.forms["example1"].checkbox1)
					disableField(document.forms["example1"].select1)
					}
				else
					{
					enableField(document.forms["example1"].text1)
					enableField(document.forms["example1"].checkbox1)
					enableField(document.forms["example1"].select1)
					}
				document.forms["example1"].text1
				}
		</script>
	</head>
	<body>
		<form name="example1">
			Disable Fields: <input type="checkbox" name="control1" onclick="toggleFields(this)" checked="checked">
			<br>
			Text Field: <input type="text" name="text1" onfocus="return onfocusField(this)">
			<br>
			Check box: <input type="checkbox" name="checkbox1" onfocus="return onfocusField(this)" onclick="return onfocusField(this)">
			<br>
			Select: <select name="select1" onfocus="return onfocusField(this)">
				<option></option>
			</select>
		</form>
		<script>
			disableField(document.forms["example1"].text1)
			disableField(document.forms["example1"].checkbox1)
			disableField(document.forms["example1"].select1)
		</script>
	</body>
</html>
Roy Sinclair is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:28 AM.


Advertisement
Log in to turn off these ads.