Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,
I am doing some practice example in javascript. I want to assign value from input box into variable and then print it via alert. However it is not working. could you please help to rectify the problem in below code. thanks.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
  
</head>
 
<body>
  
  <label for="age1">Enter your age</label>
  <input type="text" name="age"> </input>
  <button type="submit" name="Enter" > Enter </button>

   </body>
 <script type="text/javascript" > 
 function verify()
     {
    
        var userage = parseInt(document.getElementById("age").value); 
        alert (userage) ;
      
   }
   
  </script>

  
</html>
Posted

ou need to add an id="age" attribute to your input markup. "name" is not teh same as "id"
 
Share this answer
 
thanks, it worked.appreciate your help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900