views:

34

answers:

2

I want to get the current width of an html form using javascript. I'm writing this in asp.net

Form definition: <form id="form1" runat="server">

What I an trying: document.getElementById('form1').style.width

Keep producing a runtime error... Any ideas?

Thanks!

+1  A: 

Try this

document.getElementById('form1').offsetWidth
Chinmayee
I still getting an error that says "Object Required"
kralco626
Ok i used aspnetform instead of form1. So that must be the client id. But I'm getting 988 as the wdith. Not correct as the screen scrolls very far to the right. The width should be more like 3000.
kralco626
Are you sure your screen scroll because of form [or its elements]? otherwise try document.getElementById('formid').scrollWidth
Chinmayee
well everything on the page is in the form. I have <body><form>everything else</form><body> so yes the elements in the form are making the form wider, and therefore the page wider.
kralco626
well that did what it was supposed to! But i guess what i really wanted was the width of the page. any idea how to do thaT?
kralco626
+1  A: 

Have you tried this: document.body.clientWidth ?

Monika
I ended up using document.getElementById('body1').scrollWidth
kralco626