javascriptfacebox

check validate input with javascript not work in facebox


I'm using a modal facebox in register user and check validate input with java script.But java script doesn't work in facebox. Facebox Code:

<div class="adm-btn">
   <a  href="#nw-usr" rel="facebox">New User</a>
</div>

<div id="nw-usr" style="display:none">
   <input type="text" placeholder="Name" name="name" id="name" onBlur="a()">
</div>

Java Script Code:

function a(){
    var name=document.getElementById("name").value;
    var pat=/([a-z])/;
    var t=pat.test(name)
    if(name=="" || t==false){
        $("#name").css({"border-color":"#F33"})
    }
    else{
        $("#name").css({"border-color":"#3F6"})
    }
}

Solution

  • I solved it:

    function a(){
    var name=$('#facebox #name:first').val();
    var pat=/([a-z])/;
    var t=pat.test(name)
    if(name=="" || t==false){
        $(".name").css({"border-color":"#F33"})
    }
    else{
        $(".name").css({"border-color":"#3F6"})
    }
    

    }