Reputation: 35
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>
Upvotes: -1
Views: 43
Reputation: 949
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("inputid1").value;
var email = document.getElementsByClassName("gb_b gb_7a gb_R gb_3a").innerHTML;
alert("From: " +email + " Message: " + userInput);
}
</script>
<base target="_top">
<body>
<input id="inputid1" type="text" value="Write what you want the page to say">
<button onclick="alertFunction();">Enter</button>
</body>
Upvotes: 2
Reputation: 3693
You are calling alert()
recursively without any exit condition, as window.alert
refers to your implementation of alert()
itself.
If you look into your console's log you will see call stack exceeded error.
function alert() {
var userInput = document.getElementById("1").value;
var email = document.getElementsByClassName("gb_b gb_7a gb_R gb_3a").innerHTML;
alert("From: " + email + "Message: " +userInput); //This refers to your alert
}
You should rename the function as suggested in comments or if you want to override the default behaviour of the alert() function then do not call it from inside of your function.
function custom_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);
console.log("From: "+email + " Message: " + userInput);
}
Upvotes: 1