0

so heres my code

 //this is my html code
<!DOCTYPE html>
<html>
    <head>

        <link rel="stylesheet" type="text/css" href="css.css"/>

    </head>
    <body>
        <form>
            First name: <input type="text" name="FirstName" id="first" value="Mickey"><br>
            Last name: <input type="text" name="LastName" value="Mouse"><br>
            <input type="submit" value="Submit" onclick=getFirstName() />
        </form>

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
        <script type="text/javascript" src="dubs.js"></script>
    </body>
</html>

//this is my dubs.js
function getFirstName()
{
     var x= document.getElementsByName("FirstName").value;

     if( x == "Mikey")
        alert( "hello");
     else
        alert( "world" );
}

when i tried to get Firstname.value using parameter, it works, but when i try using getElementsByName,it doesnt work.....looks like my getElementsByname doesnt work,whats wrong with my code? why my var x always undefined?

Kevin Mogi
  • 117
  • 1
  • 7

0 Answers0