How do I display the value of a variable in javascript in an alert box?
For example I've got a variable x=100 and alert(x) isn't working.
the script used in grease monkey is here
var inputs = document.getElementsByTagName('input'); var new; for (i=0; i<inputs.length; i++) { if (inputs[i].getAttribute("name") == "ans") { new=inputs[i].getAttribute("value")); alert(new) } }
Making the Alert. Write the next line of code. Type "alert ("Hey, " + name + "!");". This line of code will add the variable "name" to the word "Hey, "(with the space at the end), and then add "!" to end the sentence (not required).
Displaying (Showing) TextBox value in Alert using jQuery Inside the jQuery document ready event handler, the Button has been assigned a jQuery Click event handler. When the Button is clicked, the TextBox value is retrieved and displayed in JavaScript Alert Box.
alert is a browser's way to notify user of something. It does not return anything.
The alert() method is used to show an alert box on the browser window with some message or warning. We can use it as a message or as a warning for the user. Approach: To show an alert on the browser window, we make a button.
Note, while the above answers are correct, if you want, you can do something like:
alert("The variable named x1 has value: " + x1);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With