Obese Octopus
Obese Octopus

Reputation: 101

getting a message to be displayed on javascript method

firstly i will show some code. html:

<label>Password </label> <input type="password" id="pword"><br>
<label>Confirm Password </label>  <input type="password" id="confpword" onkeyup="passwordValidation(); return false;">
<span id="themessage" class="themessage"></span><br> 

js:

function passwordValidation(){

    var username = document.getElementById("uname");
    var password1 = document.getElementById("pword");
    var confpword1 = document.getElementById("confpword");
    var themsg = document.getElementById("themessage");
    var gc = "#ff6666";

    if (password1.value == confpword1.value){
        themsg.style.color = gc;
        themsg.innerHTML = "Passwords match";
    }else{
        themsg.style.color = gc;
        themsg.innerHTML = "Passwords do not match";

    }

    }

i cant work out why nothing will show up after i start typing stuff into the input boxes. after i have 'keyed up' once typing into the confirm password box surely 1 of the 2 messages should display. i cant work out why the text is not visible.

js fiddle to show problem with current code. people can edit that if it helps

thanks

https://jsfiddle.net/z5xj4hrt/

Upvotes: 0

Views: 39

Answers (1)

Jeff Noel
Jeff Noel

Reputation: 7618

Your code works, your JSFiddle setup is just wrong.

You need to put the JavaScript code execution option as "No wrap - In head" or "No wrap - In body" if you want to call functions like that one.

OnDomReady will not keep the function.

See the corrected JSFiddle

Upvotes: 2

Related Questions