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)
}
}
A couple of things:
newas a variable name, it’s a reserved word.inputelements, you can just use thevalueproperty directly, you don’t have to go throughgetAttribute. The attribute is “reflected” as a property.name.So: