0

Im working on a 'what you see is what you get' application. You code in one box and the output is displayed in another. I need to check if a user has typed specific text within an HTML textarea, and if it's correct is will make a button visible. So far, when the user types text-align:center; the button is made visible. I can't work out so the user HAS to type 2 sets of text. So far i have this:

    $(document).ready(function(){$(".textArea").keyup(function() { // directed at the textArea div tag
     if ($(this).val().indexOf('text-decoration:underline;' && 'text-align:center;') != -1) { // if the text matches those 2 strings 
      $(".continue").css("visibility", "visible"); // make button visible
    }
      else {
                $(".continue").css("visibility", "hidden"); // keep it hidden if strings haven't been produced
          $(".correct").css("display", "block");
           }
  });
});
.continue{
background-color: #ef6d3b;
width: 6em;
text-align: center;
font-size: 15px;
border: none;
height: 25px;
color: #000000;
outline: none;
    cursor: pointer;
    border-radius: 5px;
    text-transform: uppercase;
    position: relative;
    visibility: hidden;
    
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<div class="codeArea">
            <div class="correct">
            <textarea class="textArea">
                <html>
                    <body>
                    
                        
                        
                        
                        
                        
                        
                    </body>
                </html>
                
                
 
            </textarea>
                </div>
            
        </div>

 <a href="task2.php"><button class="continue" type="button">Continue</button></a>

1 Answer 1

1

You are using wrong expression for your if statement..

if ($(this).val().indexOf('text-decoration:underline;' && 'text-align:center;') != -1)

which is evaluated same as

$(this).val().indexOf('text-align:center;') != -1

what you should really do is

$(this).val().indexOf('text-decoration:underline;')!=-1 && $(this).val().indexOf('text-align:center;')!=-1

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much!! it worked. Just needed to add a bracket at the beginning before the $ and one right at the end after the 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.