I have that code:
function change_npsize()
{
document.getElementById("np_drag").style.fontSize = document.getElementsByName("npsize").item(0).value;
};
<input type="text" name="npsize" size="2" maxlength="2" value="<?=$userinfo->npsize; ?>" onchange="change_npsize()" />
<div id="drag-container" style="position:relative;font-family:<?=$userinfo->font?>;">
<div id="np_drag" style="color:<?=$userinfo->npcolor?>; font-size:<?=$userinfo->npsize?>px;" class="draggable np_drag" style="position:absolute;left:80px;">
.::[ NowPlaying SIGnature ]::.
</div>
</div>
That code is working only in IE. I tried Firefox and Google Chrome.
I have that code:
function change_npsize()
{
document.getElementById("np_drag").style.fontSize = document.getElementsByName("npsize").item(0).value;
};
<input type="text" name="npsize" size="2" maxlength="2" value="<?=$userinfo->npsize; ?>" onchange="change_npsize()" />
<div id="drag-container" style="position:relative;font-family:<?=$userinfo->font?>;">
<div id="np_drag" style="color:<?=$userinfo->npcolor?>; font-size:<?=$userinfo->npsize?>px;" class="draggable np_drag" style="position:absolute;left:80px;">
.::[ NowPlaying SIGnature ]::.
</div>
</div>
That code is working only in IE. I tried Firefox and Google Chrome.
Share Improve this question asked Feb 19, 2011 at 8:43 CappYCappY 1,5801 gold badge17 silver badges32 bronze badges 1- 2 is there any reason you don't you also give the text input an id? – Russ Cam Commented Feb 19, 2011 at 9:00
3 Answers
Reset to default 6The proper usage of getElementsByName()
(at least in Firefox) is:
getElementsByName("npsize")[0];
The following works (at least in Chrome):
document.getElementById("np_drag").style.fontSize = document.getElementsByName("npsize")[0].value + "px";
Note the + "px"
at the end; you can’t just set it to a numeric value, you need to include the appropriate unit in the value.
I have tried this working code :
your HTML :
<input type="text" name="npsize" size="10" maxlength="2" value="small"/><br/><hr/>
<div id="np_drag">font</div>
your JavaScript :
document.getElementById("np_drag").style.fontSize = document.getElementsByName("npsize")[0].value;
See this working here.
Also, please correct me if I am wrong.
EDIT : I have changed the fiddle with your correctness at other answer.
I think this is not .fontsize ....
it might be .size