...

View Full Version : Quick and simple syntax



Local Hero
05-30-2005, 05:28 AM
Why won't this work?

if (document.forms.myform.htfront.value=checked) document.forms.orderform_16180.colorside1.value = 'Print on Front';
if (document.forms.myform.htback.value=checked) document.forms.orderform_16180.colorside2.value = 'Print on Back';
if (document.forms.myform.htrsleeve.value=checked) document.forms.orderform_16180.colorside3.value = 'Print on Right';
if (document.forms.myform.htlsleeve.value=checked) document.forms.orderform_16180.colorside4.value = 'Print on Left';

I want it to display the text if the box is checked.

Brandoe85
05-30-2005, 05:33 AM
You check the checked property, not value:

document.formName.elementName.checked

Local Hero
05-30-2005, 05:47 AM
You were right, Thanks. One more thing. The value stays even when i remove the check. How do I make it go blank again?
if (document.forms.myform.htfront.checked) document.forms.orderform_16180.colorside1.value = 'Print on Front';
if (document.forms.myform.htback.checked) document.forms.orderform_16180.colorside2.value = 'Print on Back';
if (document.forms.myform.htrsleeve.checked) document.forms.orderform_16180.colorside3.value = 'Print on Right';
if (document.forms.myform.htlsleeve.checked) document.forms.orderform_16180.colorside4.value = 'Print on Left';

glenngv
05-30-2005, 06:34 AM
Empty the value in the else block.

if (document.forms.myform.htfront.checked) document.forms.orderform_16180.colorside1.value = 'Print on Front';
else
document.forms.orderform_16180.colorside1.value = '';

or simply:

document.forms.orderform_16180.colorside1.value = (document.forms.myform.htfront.checked) ? 'Print on Front' : '';

Store the form reference in a variable to avoid excessive lookups.


var oFrm1 = document.forms.myform;
var oFrm2 = document.forms.orderform_16180;
oFrm2.colorside1.value = (oFrm1.htfront.checked) ? 'Print on Front' : '';



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum