Francisunoxx Francisunoxx - 6 months ago 10
HTML Question

Importing jQuery script won't work on html file

I created a jQuery external file

confirmPassword.js
which contain keyboard event but when I'm trying to import in my html file my external js file won't work. But when I create jQuery script under html file it work. I'm just trying to save some line of codes.

<!doctype html>
<html>
<head>
</head>
<body>

<div id = "container">

<h1>Register</h1>
<hr>

<form method = "post" action = "../process/registerProcess.php" >

<fieldset>

<div class = "form-field">
<label for = "username">Username:</label>
<input type = "text" name = "username" required>
</div>

<div class="form-field">
<label for = "userPassword">Password:</label>
<input type="password" id="userPassword">
</div>

<div class="form-field">
<label for = "userConfirmPassword">Confirm Password:</label>
<input type="password" id="userConfirmPassword" onChange="checkPasswordMatch();">
</div>

<div class="registrationFormAlert" id="divCheckPasswordMatch"> </div>

<div class = "form-field">
<input type = "submit" name = "registerSubmit" value = "Register">
</div>

<div class = "form-field">
<input type = "reset" name = "registerReset" value = "Reset">
</div>

</fieldset>

</form>

</div>
<script type = "text/javascript" src = "jQuery Compressed/jquery.js"></script> //jQuery Compressed
<script type = "text/javascript" src = "register/confirmPassword.js"></script>
</body>
</html>


confirmPassword.js

function checkPasswordMatch()
{
var password = $("#userPassword").val(); //Grab the value of userPassword.
var confirmPassword = $("#userConfirmPassword").val();

if (password != confirmPassword)
{
$("#divCheckPasswordMatch").html("Passwords do not match!");
}
else
{
$("#divCheckPasswordMatch").html("Passwords match.");
}

}

$(document).ready(function ()
{
$("#userConfirmPassword").keyup(checkPasswordMatch);
});



Answer

If I understood you correctly, you are saying your confirmPassword.js file doesn't work without jQuery, right?

You are using jQuery in your confirmPassword.js file, so you have to have jQuery imported.

EDIT: Found the problem after private chat. The paths to JS files were incorrect.

Comments