Click to See Complete Forum and Search --> : checkbox and updating a field


rjusa
11-07-2003, 02:23 PM
I'm trying to set up an instance where if a box is "checked" the information from a field is passed on to another field...the code I've tried is

function OwnEqualInsured(form[0]} {

if (document.forms[0].copy.checked)
document.forms[0].CndnOwnFirstName.value=document.forms[0].CndnInsFirstName.value;
}
</script>

<input type="checkbox" name="copy"
OnClick="OwnEqualInsured(this.form[0])" value="checkbox">

Where'd I goof?

Thanks,
Ron

Charles
11-07-2003, 02:43 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
label {display:block; margin:1em 0em}
input {margin:0 1ex}
-->
</style>

<form action="">
<div>
<label><input type="text" id="first">First</label>
<label><input type="checkbox" onclick="if (this.checked) this.form.second.value = this.form.first.value">Copy?</label>
<label><input type="text" id="second">Second</label>
<button type="submit">Submit</button>
</div>
</form>

ugaMack
11-07-2003, 02:50 PM
Try this:

function OwnEqualInsured() {

if (document.forms[0].copy.checked)
document.forms[0].CndnOwnFirstName.value=document.forms[0].CndnInsFirstName.value;
}
</script>

<input type="checkbox" name="copy"
OnClick="OwnEqualInsured()" value="checkbox">

rjusa
11-07-2003, 03:32 PM
ugaMack-

appreciate your effort...I tried the changes you suggested...seemed very logical but the program thinks otherwise! No luck...

Thanks again,
Ron

Charles
11-07-2003, 03:34 PM
You'll find that my method works just fine.

olerag
11-07-2003, 03:38 PM
Charles,

Working with some of the stuff you've published today
works great with IE6 / Net7.1 but Net4.7x shows some
pretty ugly stuff.

Does this have to do with css styles your employing?? If
so:
How do you handle old browsers OR
Am I missing something in your code that I should be doing.

Charles
11-07-2003, 03:41 PM
Originally posted by olerag
Charles,

Working with some of the stuff you've published today
works great with IE6 / Net7.1 but Net4.7x shows some
pretty ugly stuff.

Does this have to do with css styles your employing?? If
so:
How do you handle old browsers OR
Am I missing something in your code that I should be doing. Netscape 4 only half works. Disable its CSS rendering or upgrade to a browser that actually works.

rjusa
11-07-2003, 04:15 PM
Charles-

I put your code up and it does work. Problem I've got is not knowing anything 'bout CSS...

my code which grabs the 1st variable from the preceeding page and displays it on this page is

<td width="25%" height="19"><font face="Arial" size="2" color="#000000">First Name</span></font></td>
<td width="25%" height="19"><font face="Arial" size="2" color="#000000" style="text-transform: capitalize">$CndnInsFirstName$</font></td>

the code which is the 2nd variable that would normally be input is

<td width="25%"><font face="Arial">
<input type="text" name="CndnOwnFirstName" value="$CndnOwnFirstName$" onkeypress="return handleEnter(this, event)" size="20" style="text-transform: capitalize"></font></td>

so how in the heck would I use CSS in this instance???

Thanks,
Ron

ugaMack
11-07-2003, 08:23 PM
Hmmm.. that's strange that it didn't work for you. I tested it out and it seemed to work fine.

Here's my entire test page:
<HTML>
<HEAD>
<TITLE>--</TITLE>

<SCRIPT language="javascript">
function OwnEqualInsured() {

if (document.forms[0].copy.checked)
document.forms[0].CndnOwnFirstName.value=document.forms[0].CndnInsFirstName.value;
}

</SCRIPT>

</HEAD>
<BODY>

<FORM name="form1">
CndnInsFirstName: <INPUT type="text" name="CndnInsFirstName"><BR>

CndnOwnFirstName: <INPUT type="text" name="CndnOwnFirstName"><BR>

<input type="checkbox" name="copy"
OnClick="OwnEqualInsured()" value="checkbox"> </FORM>
</BODY>
</HTML>

I hope this helps :)