Skip to content Skip to sidebar Skip to footer

Enable/disable Checkbox Determind By Users Input

I've got a simple form where the user enters his contact number. If the contact number starts with 07 then the checkbox is enabled anything else I need it to be disabled. I have wr

Solution 1:

If you only want the checkbox to be enabled when the content starts with "07" you can check for that first and disable inside of the else block.

  if (document.getElementById("1").value.startsWith("07")) {
    $("#checkbox").attr("disabled", false);
    document.getElementById("divText").innerHTML = "Send text";
  }
  else
  {
    $("#checkbox").attr("disabled", true);
    document.getElementById("divText").innerHTML = "Not able to send";
  }

Solution 2:

Change your if statement to:

if(!String(document.getElementById("1").value).startsWith("07")) {...}

Post a Comment for "Enable/disable Checkbox Determind By Users Input"