Eddie Costa Domingues Eddie Costa Domingues - 7 months ago 10
Javascript Question

Somethings wrong with my javascript?

I'm trying to make a page that you type in something in the

textbox
and the page will alert the text in the
textbox
but look at the function alert it's not working please help!!!



<!DOCTYPE html>
<html>

<head>
<script>
function alert() {
var userInput = document.getElementById("1").value;
var email = document.getElementsByClassName("gb_b gb_7a gb_R gb_3a").innerHTML;
window.alert("From: ", +email + " Message: " + userInput);
}
</script>
<base target="_top">
</head>

<body>
<input id="1" type="text" value="Write what you want the page to say">
<button onclick="alert()">Enter</button>
</body>

</html>




Answer

Rename the custom function into alertFunction() since it is causing conflict with javascript built-in alert() function.

Try the following code:

<script>
    function alertFunction() {
      var userInput = document.getElementById("1").value;
      var email = document.getElementsByClassName("gb_b gb_7a gb_R gb_3a").innerHTML;
      window.alert("From: ", +email + " Message: " + userInput);
    }
</script>
<base target="_top">

<body>
  <input id="1" type="text" value="Write what you want the page to say">
  <button onclick="alertFunction();">Enter</button>
</body>