Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alert a variable value

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)    } } 
like image 548
technocrat Avatar asked Jun 06 '10 06:06

technocrat


People also ask

How do you alert a variable?

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).

How do I get value in alert box?

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.

What does alert () return?

alert is a browser's way to notify user of something. It does not return anything.

What is the purpose of the alert () method?

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.


1 Answers

Note, while the above answers are correct, if you want, you can do something like:

alert("The variable named x1 has value:  " + x1); 
like image 75
JosephDoggie Avatar answered Sep 22 '22 01:09

JosephDoggie