Ticker

6/recent/ticker-posts

Header Ads Widget

Responsive Advertisement

Javascript - Input from the user

How to take input from the user, using javascript:

Look at the simple example below:

<!DOCTYPE html>
<html>
<head>
<title>InputFromUser</title>
<script type= "text/javascript">
function Input(){
var Username = document.getElementById("text").value;
alert("Successfully signed up!");
}
</script>
</head>
<body>
<input id="text" placeholder= "Username">
<button onClick = "Input();">SignUp</button>
</body>
</html>

EXPLANATION OF THE EXAMPLE:

  • In this example, we are starting with the basic syntax of javascript that we have discussed earlier. Check this Post Basic Syntax of Javascript .
  • The function body contains the declaration of variable identified as "Username".
  • The variable is assigned as document.getElementById(""text).value.
  • Here document is object and getElementById("text") is a function that contains the id "text", whereas value is the property of that function.
  • alert is the function to have an alert message.
  • Inside the body , input is the tag which input something from the user.
  • Try this code.

Post a Comment

0 Comments