By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,044 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,044 IT Pros & Developers. It's quick & easy.

textbox width

P: n/a
<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?
Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"Alex" <al******************@remove.this> wrote in message
news:Pz*******************@twister.rdc-kc.rr.com...
<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" >
Jul 23 '05 #2

P: n/a
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???
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:ke********************@comcast.com...
"Alex" <al******************@remove.this> wrote in message
news:Pz*******************@twister.rdc-kc.rr.com...
<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" >

Jul 23 '05 #3

P: n/a
Alex wrote:
<input type="textbox" id="myTxt" value="what's my width?" onClick="alert(this.width)"> <snip> how can I get a handle on the width of that textbox? Or can I at all?


This works in my IE 6, Netscape 7.2, Firefox 1.0

function showwidth(){
t=document.getElementById('txt1');
alert(t.offsetWidth);
}

<input type="textbox" id="txt1" value="what's my width?">
Jul 23 '05 #4

P: n/a
Alex wrote:
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???


Did you try this approach:

d=document.getElementById(objectID);
alert(d.offsetHeight);

The first 2 links show browser support:

http://www.quirksmode.org/js/doctypes.html
http://www.evolt.org/article/documen...655/index.html
http://msdn.microsoft.com/workshop/a...ffsetwidth.asp

Mike
Jul 23 '05 #5

P: n/a
Alex wrote:
<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>

--
Rob
Jul 23 '05 #6

P: n/a
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!
"mscir" <ms***@yahoo.com> wrote in message
news:11*************@corp.supernews.com...
Alex wrote:
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???


Did you try this approach:

d=document.getElementById(objectID);
alert(d.offsetHeight);

The first 2 links show browser support:

http://www.quirksmode.org/js/doctypes.html
http://www.evolt.org/article/documen...655/index.html
http://msdn.microsoft.com/workshop/a...ffsetwidth.asp

Mike

Jul 23 '05 #7

P: n/a
Alex wrote:
... Do you know of a good JS reference?


Google for "JavaScript 1.5 reference" and you'll find lots of them.

http://www.programmershelp.co.uk/javascriptref.php
http://www.byteshift.de/javascript-1415/CoreGuideJS15/
http://synchro.net/docs/js/ref/ix.html
http://www.croczilla.com/~alex/refer...avascript_ref/

I learned a LOT (including offsetWidth) from this newsgroup. When I run
into problems I use Google, and search this newsgroup to see if similar
problems have been solved here.

Also, please don't top post, it throws off the Q&A flow.
Good Luck,
Mike
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.