MarshyM MarshyM - 1 year ago 66
HTML Question

When particular text is entered, make the button clickable

How to make a button clickable when a particular text is entered.
Example: When 'allow me' is entered, the button 'get in here' should be enable to be clicked. JS or jQuery is fine.


Here's some code:


require_once 'includes/main.php';

Handle visits with a login token. If it is
valid, log the person in.


// Is this a valid login token?
$user = User::findByToken($_GET['tkn']);


// Yes! Login the user and redirect to the protected page.


// Invalid token. Redirect back to the login form.

Handle logging out of the system. The logout
link in protected.php leads here.


$user = new User();



Don't show the login page to already
logged-in users.

$user = new User();


Handle submitting the login form via AJAX


if(!empty($_POST) && isset($_SERVER['HTTP_X_REQUESTED_WITH'])){

// Output a JSON header

header('Content-type: application/json');

// Is the email address valid?

if(!isset($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
throw new Exception('Please enter a valid email.');

// This will throw an exception if the person is above
// the allowed login attempt limits (see functions.php for more):

// Record this login attempt
rate_limit_tick($_SERVER['REMOTE_ADDR'], $_POST['email']);

// Send the message to the user

$message = '';
$email = $_POST['email'];
$subject = 'Your Login Link';

$subject = "Thank You For Registering!";
$message = "Thank you for registering at our site!\n\n";

// Attempt to login or register the person
$user = User::loginOrRegister($_POST['email']);

$message.= "You can login from this URL:\n";
$message.= get_page_url()."?tkn=".$user->generateToken()."\n\n";

$message.= "The link is going expire automatically after 10 minutes.";

$result = send_email($fromEmail, $_POST['email'], $subject, $message);

throw new Exception("There was an error sending your email. Please try again.");

'message' => 'Thank you! We\'ve sent a link to your inbox. Check your spam folder as well.'
catch(Exception $e){

'message' => $e->getMessage()

Output the login form


<!DOCTYPE html>

<meta charset="utf-8"/>

<link href=",700" rel="stylesheet">

<!-- The main CSS file -->
<link href="assets/css/style.css" rel="stylesheet" />

<!--[if lt IE 9]>
<script src=""></script>


<form id="login-register" method="post" action="index.php">

<h1>Login or Register</h1>

<input type="text" placeholder="" name="email" autofocus />
<p>Enter your email address above and we will send <br />you a login link.</p>

<button type="submit">Login / Register</button>



<!-- JavaScript Includes -->
<script src="" integrity="sha256-cCueBR6CsyA4/9szpPfrX3s49M9vUU5BgtiJj06wt/s=" crossorigin="anonymous"></script>
<script src="assets/js/script.js"></script>


I need the button with Login / Register to be enabled if a particular email is entered.

Answer Source

Set <button> element disabled attribute, <button disabled>click</button>. Attach input event listener to element where text is entered by user using .addEventListener. Within input event handler check if user entered exact phrase using strict equality operator text === text, if condition is true remove disabled attribute from <button> element, else set disabled attribute at <button> element.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download