-4

Here it's working: https://jsfiddle.net/w711Lf6t/1/

On page don't working. index.php

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css.css">
<script src="js.js"></script>
</head>
<form action="register" method="post">
    <input type="text" name="name" id="name" class="input_class" placeholder="test"/>
        <div id="error_name">Input name!</div>
</form>
</html>

js.js

function validation() {
    var name = $("#name").val();
    if (name === '') {
        $("#error_name").css('display', 'block');
    }
    else
    {
        $("#error_name").css('display', 'none');
    }
}

$("#name").focusout(function () {
    validation();
});

css.css

#error_name {
    font-family: Arial;
    color: red;
    display: none;
}

What I forget to add? I try jquery .js, but same problem.

Deimantas
  • 13
  • 6

1 Answers1

0

You need to include Jquery before your js file:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css.css">
<script src="jquery.min.js"></script>
<script src="js.js"></script>
</head>
<form action="register" method="post">
    <input type="text" name="name" id="name" class="input_class" placeholder="test"/>
        <div id="error_name">Input name!</div>
</form>
</html>
Ahmad Mobaraki
  • 7,426
  • 5
  • 48
  • 69