Search code examples
javascriptstringlowercase

Can I add text.toLowerCase(); to an already functioning script?


I'm using this script:

    function validateform() {
  var textarea = document.getElementById('textareabox');
  var word = '<?php echo $answerbutton_of_this_page ?>';

  var textValue = textarea.value;
  if (textValue.indexOf(word) != -1) {
    document.getElementById("correcto").innerHTML = '<?php echo $outputvali_of_this_page; ?>';
    return true;
  } else {
    document.getElementById("incorrecto").innerHTML = 'Incorrect!';
  }
}

I'd like to add:

document.getElementById("textareabox").value = text.toLowerCase();

But I cannot get it to work. Where or how should I add this? I want the script to first lowercase the input and then see if the user has the correct / incorrect answer.


Solution

  • Just change:

    var textValue = textarea.value;
    

    To:

    var textValue = textarea.value.toLowerCase();