P.A
P.A

Reputation: 23

Change size based on value

Here is my code:

var changeValue = document.getElementById("fontSize");
changeValue.value= 400;

var changeSign = document.getElementById("Box");
changeSign.style.width = ?;

I would like to change the box width based on the "fontSize" value, in this case 400.

Upvotes: 2

Views: 43

Answers (2)

Paulo Lima
Paulo Lima

Reputation: 76

I'm assuming that you want to change the box width WHEN the value is changed.

In this case you need an Event:

var changeValue = document.getElementById("fontSize");
    changeValue.value= 100;
    changeValue.onchange = function(){
    var changeSign = document.getElementById("Box");
    changeSign.style.width = this.value+'px';
    };
 <input id='fontSize'>
    <div id='Box' style="background-color: red; width: 100px; height: 100px">
 

You could also:

  • Create a button
  • Attach another event

Upvotes: 0

Thomas Landauer
Thomas Landauer

Reputation: 8355

Is this what you're asking for? changeSign.style.width = changeValue.value + 'px'

Upvotes: 1

Related Questions