Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Checkbox - Change Font Color

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Checkbox - Change Font Color

    I have a form with 3 checkboxes. When user checks one of the boxes, additional fields show beneath the checkbox and the other 2 checkboxes are grayed out (locked). What I want is that when a user checks a checkbox, not only does the other 2 lock, but the text associated with them turn a different font color. I want it to appear as if the other checkboxes and text are being grayed out. BTW - I don't know any java, someone helped me with this and gave me this code so please try to be as specifica as possible.

    For the lock function, I am using the following code:

    <script language=JavaScript> var U=0;L=1; // (U)nlocked & (L)ocked
    function doIt(_v)
    {
    if(eval("document.bgcheck.c"+_v+".checked"))
    {

    if(_v==2){lock(3);lock(4);}
    if(_v==3){lock(2);lock(4);}
    if(_v==4){lock(2);lock(3);}
    }
    else
    {

    if(_v==2){unlock(3);unlock(4);}
    if(_v==3){unlock(2);unlock(4);}
    if(_v==4){unlock(2);unlock(3);}
    }
    }
    function lock(_v)
    {
    eval("document.bgcheck.c"+_v+".disabled=true"); // IE thing
    eval("document.bgcheck.h"+_v+".value=L");
    eval("document.bgcheck.h"+_v+".name=''");
    }
    function unlock(_v)
    {
    eval("document.bgcheck.c"+_v+".disabled=false"); // IE thing
    eval("document.bgcheck.h"+_v+".value=U");
    eval("document.bgcheck.h"+_v+".name=document.bgche ck.h"+_v+".id");
    }
    function whipe(_v)
    {
    eval("document.bgcheck.c"+_v+".checked=false");
    }

    </script>

    Here's my checkboxes code. The document.getElementById('showMeOnClick1').style.di splay=(this.checked)?'inline':'none'; doIt(4)" code is when the user checks the box the additional fields appear.

    <tr><td>Package 1<input type="checkbox" name="package1" id="package1" value="Package1" onclick="document.getElementById('showMeOnClick1') .style.display=(this.checked)?'inline':'none'; doIt(4)" /><input type=hidden name=h4 value=0> </td></tr>

    <div id="showMeOnClick1" style="display:none">
    <span class="red_font">Please complete the information below as additional information is required for Package 1.</span>
    <table>
    <tr><td><p><strong>Enter your shirt sizes:</strong><br /></p></td></tr>
    <tr><td>
    <input name="size1" id="size1" type="text" value="" size="30">
    <input name="size2" id="size2" type="text" value="" size="30">
    <input name="size3" id="size3" type="text" value="" size="30">
    </td></tr></table>
    </div>

    <tr><td>Package 2<input type="checkbox" name="package2" id="package2" value="Package2" onclick="document.getElementById('showMeOnClick2') .style.display=(this.checked)?'inline':'none'; doIt(3)" /><input type=hidden name=h4 value=0> <div id="showMeOnClick2" style="display:none"> </td></tr>

    <div id="showMeOnClick2" style="display:none">
    <span class="red_font">Please complete the information below as additional information is required for Package 1.</span>
    <table>
    <tr><td><p><strong>Enter your desired colors:</strong><br /></p></td></tr>
    <tr><td>
    <input name="color1" id="color1" type="text" value="" size="30">
    <input name="color2" id="color2" type="text" value="" size="30">
    <input name="color3" id="color3" type="text" value="" size="30">
    </td></tr></table>
    </div>

    <tr><td>Package 3<input type="checkbox" name="package3" id="package3" value="Package3" onclick="document.getElementById('showMeOnClick3') .style.display=(this.checked)?'inline':'none'; doIt(2)" /><input type=hidden name=h4 value=0> </td></tr>

    <div id="showMeOnClick3" style="display:none">
    <span class="red_font">Please complete the information below as additional information is required for Package 1.</span>
    <table>
    <tr><td><p><strong>Enter your desired state:</strong><br /></p></td></tr>
    <tr><td>
    <input name="state1" id="state1" type="text" value="" size="30">
    <input name="state2" id="state2" type="text" value="" size="30">
    <input name="state3" id="state3" type="text" value="" size="30">
    </td></tr></table>
    </div>


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: Checkbox - Change Font Color

    This is a Java forum, not a JavaScript forum. Please do not make the mistake of beleiving they are the same thing. They are completely different!

    Regards,
    Chris

Similar Threads

  1. How to Change JTextArea font, font size and color
    By Flash in forum Java Swing Tutorials
    Replies: 7
    Last Post: January 14th, 2012, 10:47 PM
  2. Need help with setting multiple font styles in jTextPane
    By jch02140 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 23rd, 2010, 06:16 AM
  3. how to delete record based on checkbox selected checkbox
    By -_- in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: December 15th, 2009, 09:26 PM
  4. How prograssbarColor with differentThe color indicates
    By NARs in forum AWT / Java Swing
    Replies: 0
    Last Post: October 18th, 2009, 10:04 PM
  5. setEnabled causing checkbox to deselect
    By dewboy3d in forum AWT / Java Swing
    Replies: 3
    Last Post: May 21st, 2009, 11:36 AM

Tags for this Thread