Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

width value as a varable

Status
Not open for further replies.

vishalmarya

Programmer
Aug 19, 2001
28

i need to set the value to a width element of the style attribute of button control.

Like :

Code:
<input type="submit" name="btn1" value="Button" id="btn1" style="width:100px;" />


But how can i provide the value as a variable instead of hardcoded one. i don't want to achieve this through separate javascript statement.
 
[1]
[tt]var elem=document.getElementById("btn1");
//the right-hand-size can be fed through a variable, sure, as requested
elem.style.width=123+"px"; //some number + unit of measure[/tt]

[2] As an application of the idea, if you want to double the width, it is like this. There is an elaboration in it which is for the purpose of preserving the original unit of measure.
[tt]
var elem=document.getElementById("btn1");
var w=elem.style.width;
elem.style.width=2*parseFloat(w)+w.replace(/[\d.,]/g,"");[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top