javascript – alert a variable value
javascript – alert a variable value
Note, while the above answers are correct, if you want, you can do something like:
alert(The variable named x1 has value: + x1);
A couple of things:
- You cant use
new
as a variable name, its a reserved word. - On
input
elements, you can just use thevalue
property directly, you dont have to go throughgetAttribute
. The attribute is reflected as a property. - Same for
name
.
So:
var inputs, input, newValue, i;
inputs = document.getElementsByTagName(input);
for (i=0; i<inputs.length; i++) {
input = inputs[i];
if (input.name == ans) {
newValue = input.value;
alert(newValue);
}
}
javascript – alert a variable value
show alert box with use variable with message
<script>
$(document).ready(function() {
var total = 30 ;
alert(your total is :+ total +rs);
});
</script>