Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 12th, 2003, 12:15 PM
jonathen jonathen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Essex, UK
Posts: 44 jonathen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
form fields locked using checkbox

Hi all,

I wonder if someone could help. I have a form with several fields - it is an editable form, for editing data grabbed from a database. However, I want to ensure that the user doesn't accidentally make changes they do not mean to. What I'd like to have is a checkbox on the form labelled "Read Only" which is ticked by default, causing all form fields to be locked in read-only status. When the user unchecks this box, all fields are unlocked and available for editing.

Trouble is, I can't figure out how to do this efficiently.

Any ideas?

Thanks in advance,

Jon

Reply With Quote
  #2  
Old November 12th, 2003, 02:15 PM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: form fields locked using checkbox

I hope this will solve your problem:
Code:
<html>
<head>
<title>Test</title>
<script language="javascript">
function lockBox()
{
	if(document.form1.readonly.checked==true)
		document.form1.readonly.focus();
}
</script>
</head>
<body>
<form name="form1">
<input type=checkbox name="readonly" checked> Read Only<br><br>
First name : <input type=text name="fname" value="John" onFocus="lockBox()"><br>
Middle name : <input type=text name="mname" value="White" onFocus="lockBox()"><br>
Last name : <input type=text name="lname" value="Ransom" onFocus="lockBox()"><br>
</form>
</body>
</html>

Reply With Quote
  #3  
Old November 12th, 2003, 02:25 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: form fields locked using checkbox

here is a little script I cooked up that does what you need it to do. Make sure to set all the form fields to readonly by default and add an onclick event to the checkbox.

Code:

<html>
<head>
<title>Page title</title>
<script type="text/javascript">
<!--
function disable_form1() {
for ( var i=0; i<document.form1.elements.length; i++ ) {
	if(document.form1.elements[i].readOnly==true){
	document.form1.elements[i].readOnly=false
	 }else{
	 document.form1.elements[i].readOnly=true
	 	 }
}
}
// -->
</script>
</head>
<body>
<form action="" method="post" name="form1">
<input type="checkbox" name="setstatus" checked onClick="disable_form1()"/>Read Only<br>
<input type="text" name="test1" value="1" readonly="true"/><br>
<input type="text" name="test1" value="2" readonly="true"/><br>
<input type="text" name="test1" value="3" readonly="true"/>
</form>
</body>
</html>


let me know if you have any questions!!

Reply With Quote
  #4  
Old November 12th, 2003, 02:38 PM
jonathen jonathen is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Essex, UK
Posts: 44 jonathen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: form fields locked using checkbox

Thanks so much for that! I didn't expect to be given the code, so that was a nice surprise. It is greatly appreciated

Jon

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > form fields locked using checkbox


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway