mercredi 22 juillet 2015

else is running always if i remove (else code) everything working fine ...please help me

question---if i remove else part of code everything working fine even if statment is correct it executing else part also .wht this happening and how can i resolve this please help me i am new in javaScript

<!DOCTYPE html>
<html>
    <head>
        <title>Priject 2</title>
    </head>
    <body>
        <label>Name:
            <input type="text" id="name">
        </label>
        <input type="submit" id="fetch">
        <br />
        <dl>

        <dt>Age</dt>
        <dd class="age">-</dd>

        <dt>Location</dt>
        <dd class="location">-</dd>

        <dt>job</dt>
        <dd class="job  ">-</dd>

        <script src="jquery-1.11.1.js"></script>
        <script></script>
        </dl>

        <script src="jquery-1.11.1.js"></script>
        <script>

            var people=[{
                name:"alex",
                age:20,
                location:"canada",
                job:"web developer"
            },
            {
                name:"aliana",
                age:21,
                location:"japan",
                job:"teacher"
                    }
            ]
            for(i=0;i<people.length;i++){
              result(people[i])
              }

            function result(data){
                $("#fetch").on("click",function(){
                     var name=$("#name").val();
                     if(data.name ===name ){
                        $(".age").text(" ");
                        $(".job").text(" ");
                        $(".location").text(" ");

                       $(".age").append(data.age);
                        $(".job").append(data.job);
                        $(".location").append(data.location);
                        } 
                    else if(data.name != name) {
                        $("body").text(" ")
                        noresult();
                        }
                 })


            }
            function noresult(){

            var noresult="<div><p>name is not in database </p></div>";
                $("body").append(noresult);
            }

                </script>
    </body>
</html>

Aucun commentaire:

Enregistrer un commentaire