0

here is my function:

function passwordValidation(){

    var uname = document.getElementById("pword1").value;
    var pword = document.getElementById("cPassword").value;

    var matchCol = "#009900";
    var noMatchCol = "#CC0000";
    var noBg = "#FFFFFF";


    if (uname.length < 1){
        cPassword.style.backgroundColor = noBg;
        match = "";
    }else if (uname.length < 6){
            $('document').ready(function(){
                $('#myToolTip').tooltip();
            });
    }else if (pword.length < 1){
        cPassword.style.backgroundColor = noBg;
        match = "";
    }else if (pword1.value == cPassword.value){
        match = "Match!";
        cPassword.style.backgroundColor = matchCol;
    } else if  (pword1.value != cPassword.value){
        match = "No Match!";
        cPassword.style.backgroundColor = noMatchCol;
    }
    document.getElementById("combination").innerHTML = match;
}

this function works fine without the first else if. but once i include it, nothing will work. interestingly, if i put the else if isolated on it's own it also works. well actually, this works:

$('document').ready(function(){
                $('#myToolTip').tooltip();

how can i combine the 2 so that when the user enters something less than 6 characters, the tooltip will flash up telling them what they need to change

4
  • This code is getting progressively worse as your questions about it continue.
    – Jamiec
    Nov 28, 2014 at 13:51
  • The first if statement that validates as true will be fired. So you have to figure out a good way of organizing your validations. As a sidenote; the document.ready wrapper should not be within the if statement. Nov 28, 2014 at 13:53
  • @Jamiec please explain?
    – BlueShark
    Nov 28, 2014 at 14:58
  • @Baszz that was going to be the central point of my next question. is there a good way to be able to run lots of different scripts or if statements so that you can have multiple things running? because currently my if statement is just expanding and like you said, as soon as one hits true the others will not even be trialed. is there a neat tidy way?
    – BlueShark
    Nov 28, 2014 at 15:00

2 Answers 2

0

You dont need a $(document).ready() here, just use

else if (uname.length < 6){
    $('#myToolTip').tooltip();
}

(As an aside, if you did want a document ready, it cant be within an if statement like this, and there should be no quotes round the document bit)

0

I think that what you want is this:

$(function() {
    $('#pword1').tooltip();
    $('#pword1').tooltip( "disable" );
    $(".ui-helper-hidden-accessible").hide();
});

function passwordValidation(){

    var uname = document.getElementById("pword1").value;
    var pword = document.getElementById("cPassword").value;
    var cPassword = document.getElementById("cPassword");

    var matchCol = "#009900";
    var noMatchCol = "#CC0000";
    var noBg = "#FFFFFF";

    var match ="";
    if (uname.length < 1){
        cPassword.style.backgroundColor = noBg;
        match = "";
    }else if (uname.length < 6){
        $('#pword1').tooltip( "enable" );
        $('#pword1').tooltip("open");
    }else if (pword.length < 1){
        cPassword.style.backgroundColor = noBg;
        match = "";
    }else if (pword1.value == cPassword.value){
        match = "Match!";
        cPassword.style.backgroundColor = matchCol;
    } else if  (pword1.value != cPassword.value){
        match = "No Match!";
        cPassword.style.backgroundColor = noMatchCol;
    }
    document.getElementById("combination").innerHTML = match;
}

The tooltip is disabled when the page loads. It is enabled and shown when the user clicks validation button and your condition is met.

Here is a fiddle: http://jsfiddle.net/4wrj6da3/

2
  • copied and pasted this over my function just to see what it would do and nothing worked. do you know why? html need editing?
    – BlueShark
    Nov 28, 2014 at 14:58
  • Updated my answer with a fiddle.
    – M. Page
    Nov 28, 2014 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.