textbox width

A

Alex

<html>
<body>
<form>
<input type="textbox" id="myTxt" value="what's my width?"
onClick="alert(this.width)">
</form>
</body>
</html>

how can I get a handle on the width of that textbox? Or can I at all?
 
M

McKirahan

Alex said:
<html>
<body>
<form>
<input type="textbox" id="myTxt" value="what's my width?"
onClick="alert(this.width)">
</form>
</body>
</html>

how can I get a handle on the width of that textbox? Or can I at all?

Probbaly not what you want but you can set it.

<input type="textbox" style="width:100px" >
 
A

Alex

right, and i'm aware of that... how would you then--ever--be able to
determine the height of an object on a page?? not even when a stylesheet
style is set does it seem to work?!

ANY ideas???
 
R

RobG

Alex said:
<html>
<body>
<form>
<input type="textbox" id="myTxt" value="what's my width?"
onClick="alert(this.width)">
</form>
</body>
</html>

how can I get a handle on the width of that textbox? Or can I at all?

<form action="">
<input type="textbox" id="myTxt" value="what's my width?"
onClick="
var msg;
var elem = this;

// IE method
if (elem.currentStyle) {
msg = elem.currentStyle['width'];

// W3C method
} else if (window.getComputedStyle) {
var compStyle = window.getComputedStyle(elem, '');
msg = compStyle.getPropertyValue('width');
} else {
msg = 'The methods I tried ain\'t '
+ 'supported by your browser.';
}

alert(msg)">
</form>

However, you will notice that IE very helpfully returns "auto" if
you haven't specified a width. Firefox gives a response in px.

Courtesty of:


<URL:http://www.oreillynet.com/pub/a/javascript/excerpt/JSDHTMLCkbk_chap5/index5.html>
 
A

Alex

suh-weet!!

Mike, that's spot-on EXACTLY what I was looking for. thanks so much! Do you
know of a good JS reference?

thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top