Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2005
    Location
    Utah
    Posts
    64
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Quick and simple syntax

    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.

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    You check the checked property, not value:

    document.formName.elementName.checked

  • #3
    New Coder
    Join Date
    May 2005
    Location
    Utah
    Posts
    64
    Thanks
    6
    Thanked 0 Times in 0 Posts
    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';

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Empty the value in the else block.
    Code:
    if (document.forms.myform.htfront.checked)   document.forms.orderform_16180.colorside1.value = 'Print on Front';
    else
      document.forms.orderform_16180.colorside1.value = '';
    or simply:
    Code:
    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.
    Code:
    var oFrm1 = document.forms.myform;
    var oFrm2 = document.forms.orderform_16180;
    oFrm2.colorside1.value = (oFrm1.htfront.checked) ? 'Print on Front' : '';


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •