facebook

javascript to change the color of a text if a box is checked

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #337398 Reply

    sadimishal
    Member

    hi
    i need your help.
    I need the javascript to change the color of a text if a checkbox is checked. for the button onclick
    thanks

    #337408

    Brandon
    Member

    Untested code off the top of my head but should give you an idea:

    
    if ( $('#form1-checkbox1 > input').attr('checked'))
    {
     $('#form1-screen-text1').css('color','red');
    }
    
    #337430

    sadimishal
    Member

    Unfortunately it didn’t work.

    #337433

    support-michael
    Keymaster

    @sadimishal

    Let’s take the guess work out. Post a small example so we know exactly what you are trying to do.

    #337441

    sadimishal
    Member

    I want to make a quiz.
    I’ll have this question :
    What’s the capital of England?
    Students will write the answer in a textfield called textField1, then they will click a button to check their answers.

    I want this:
    If the answer is ‘London’ , the textfield background will be green, otherwise it will be red. that’s it.
    thanks for your help.

    #337446

    Brandon
    Member

    Try this:

    myAnswer = $('#m1-formname-textField1').val();
    if (  myAnswer == 'London')
    {
     $('#m1-formname-textField1').css('background-color','green');
    }else
    { $('#m1-formname-textField1').css('background-color','red');}
    
    
Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: javascript to change the color of a text if a box is checked

You must be logged in to post in the forum log in