Click here to Skip to main content
15,900,705 members

Comments by Member 13858049 (Top 2 by date)

Member 13858049 5-Jun-18 8:32am View    
i did fore it an own question thread: https://www.codeproject.com/Questions/1247127/Jquery-code-does-not-work
Member 13858049 5-Jun-18 8:21am View    
Thank you for your answer, however : I have now a try of the jquery code which is translated from JavaScript , by this translation of the code above, however it does not work with the example html (with the javaskript stuff it did work),it should color red or green the input if somebody enter a correct word from the datalist or not, Mabey somebody can help, I do not now what I do wrong:

let btn = $("#btnSend");
let form = $("#zeForm");
let input = $("#zeInput");
let msg = $("#msg");
let allowedValues = ["atown", "btown", "ctown"]; // same values as the options in your datalist


btn.on('click' , function() {
    let allGood = false;

    allowedValues.each(function(index, element) {
        if (element === input.value) {
            allGood = true;
            return;
        }
    })

    if (allGood) {
        msg.text("Success!!");
        msg.attr('style',"color:green");
        //form.submit();
    } else {
         msg.text("This value is not accepted";
         msg.attr('style',"color:red");
    }
   msg.attr('style',"display:inline");

});