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:

  1. You cant use new as a variable name, its a reserved word.
  2. On input elements, you can just use the value property directly, you dont have to go through getAttribute. The attribute is reflected as a property.
  3. Same for name.


var inputs, input, newValue, i;

inputs = document.getElementsByTagName(input);
for (i=0; i<inputs.length; i++) {
    input = inputs[i];
    if ( == ans) {   
        newValue = input.value;

javascript – alert a variable value

show alert box with use variable with message

$(document).ready(function() {
var total = 30 ;
alert(your total is :+ total +rs);

Leave a Reply

Your email address will not be published.