Nikolas Kim
Nikolas Kim

Reputation: 1

How can I assign a javascript variable in html format?

For example, there is a page like below.

<html>
<head>
<title>Variables!!!</title>
<script type="text/javascript">
var lookatthis = 11;
var one = 22;
var two = 3;
var add = one + two;
var minus = one - two;
var multiply = one * two;
var divide = one/two;
    document.write("First No: = " + one + "<br />Second No: = " + two + " <br />");
    document.write(one + " + " + two + " = " + add + "<br/>");
    document.write(one + " - " + two + " = " + minus + "<br/>");
    document.write(one + " * " + two + " = " + multiply + "<br/>");
    document.write(one + " / " + two + " = " + divide + "<br/>");
</script>
</head>
<body>
</body>
</html>

I want to assign the javascript variable "lookatthis" on debug console.

//apologise for my ambiguous question. I would rather say, "I want to assign new value to variable "lookatthis" on this web-page using console on explorer."

Thank you for your kind teaching.)

Upvotes: 0

Views: 517

Answers (5)

ProblemsEverywhere
ProblemsEverywhere

Reputation: 547

If what you want is to be able to 'set' the value of lookatthis, you can use an input and using jquery or pure js get the value of the input and assign it to 'lookatthis'.

Edit: You can also use in the chrome console: lookatthis=25 but as your script loads when page loads, changes will not be shown but the value will be changed

Upvotes: 0

Dzmitry Aleinik
Dzmitry Aleinik

Reputation: 16

You achieve it by using prompt function

var lookatthis = prompt('Type the lokaltthis value');

Upvotes: 0

Alex
Alex

Reputation: 1423

Open debug console and write there:

lookatthis = 20

But this get you nothing

Upvotes: 1

Richard Uie
Richard Uie

Reputation: 161

Anywhere in your script block after your initial assignment of lookatthis, you can write the value to the console with the command:

console.log(lookatthis);

Upvotes: 0

NiVeR
NiVeR

Reputation: 9786

You can use the log method:

console.log(lookatthis);

Upvotes: 0

Related Questions