|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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>
|
|
#3
|
|||
|
|||
|
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!! |
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > form fields locked using checkbox |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|