Thanks much Matthew and Bobby!

The script works as I wanted. I need it to override whatever the user puts in 
there when the check the box and clear the fields when unchecked.

-----Original Message-----
From: Bobby Hartsfield [mailto:[EMAIL PROTECTED]
Sent: Monday, November 21, 2005 4:21 PM
To: CF-Talk
Subject: RE: JavaScript Autofill


<input type="checkbox" onclick="if ( this.checked )
{copyData()}else{document.forms[0].reset();}">

If you have any other forms on the page BEFORE this form, increment forms[0]
accordingly.

...:.:.:.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com

-----Original Message-----
From: Orlini, Robert [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 21, 2005 3:53 PM
To: CF-Talk
Subject: RE: JavaScript Autofill

One more thing Matthew. 

What do I add to this code so that when I uncheck the box the values
disappear as well??

-----Original Message-----
From: Orlini, Robert 
Sent: Monday, November 21, 2005 3:49 PM
To: 'cf-talk@houseoffusion.com'
Subject: RE: JavaScript Autofill


Perfect Matthew. Thanks. Got to brush up more on JavaScript.

-----Original Message-----
From: Matthew Walker [mailto:[EMAIL PROTECTED]
Sent: Monday, November 21, 2005 3:35 PM
To: CF-Talk
Subject: RE: JavaScript Autofill


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
 










~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:224951
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=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to