You have two fields with the id "lname". Generally, you should only use
an id once per page. That JavaScript hurts my eyes so I haven't
bothered trying to understand it. Are you trying to copy a set of values
from a set of hidden fields to a set of visible fields? Something like
this is low tech but very easy to understand....
<script>
function copyData() {
document.getElementById('field1').value =
document.getElementById('default1').value;
document.getElementById('field2').value =
document.getElementById('default2').value;
document.getElementById('field3').value =
document.getElementById('default3').value;
}
</script>
<form>
<input type="hidden" id="default1" value="Spare">
<input type="hidden" id="default2" value="Spare">
<input type="hidden" id="default3" value="Spare">
<input type="checkbox" onclick="if ( this.checked ) copyData()">
Field 1: <input name="field1" type="text" id="field1">
Field 2: <input name="field2" type="text" id="field2">
Field 3: <input name="field3" type="text" id="field3">
</form>
-----Original Message-----
From: Orlini, Robert [mailto:[EMAIL PROTECTED]
Sent: Tuesday, 22 November 2005 9:01 a.m.
To: CF-Talk
Subject: OT: JavaScript Autofill
I have a JavaScript that I hoped would autofill some fields when a user
clicks a checkbox, but it doesn't. I will admit I not a JavaScript
programmer and copied and tweaked some code. The bold areas I edited to
try to make it work but autofilling with the word "spare", but it
doesn't do anything.
Anyone can help here please? Thanks in advance.
<script type="text/javascript" language="javascript"> function
setname(box) { var f = box.form, b_which = box.checked, from_el, to_el,
i = 0; var fld_name = new Array('lname'); while (from_el =
f[fld_name[i]]) { to_el = f[fld_name[i++]]; to_el.value = b_which ?
from_el.value : ''; if (to_el.readOnly != null) to_el.readOnly = b_which
? true : false; else to_el.onfocus = b_which ? function() {this.blur();
}
: null;
}
}
</script>
<form>
<input name="lname" type="hidden" id="lname" value="Spare">
<input type="checkbox" name="spare" onclick="setname(this)">
Name: <input name="lname" type="text" id="lname">
</form>
Robert O. at HWW
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.362 / Virus Database: 267.13.4/176 - Release Date:
11/20/2005
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Discover CFTicket - The leading ColdFusion Help Desk and Trouble
Ticket application
http://www.houseoffusion.com/banners/view.cfm?bannerid=48
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:224859
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54