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)
}
}
Note, while the above answers are correct, if you want, you can do something like:
alert("The variable named x1 has value: " + x1);