Change iFrame width and height on submit.

I have a form as such:
<form action="showPage.php" method="post" target="virtualDisplay">
Width : <input type="text" name="viewWidth" value="" /> x Height: <input type="text" name="viewHeight" value="" />
<button type="submit">try me.</button>

When the form is submitted, I want to change the height/width of an iframe located on the same page (via JavaScript):
<iframe src ="showPage.php" width="xxxx" height="xxxx" name="virtualDisplay">
  <p>Your browser does not support iframes.</p>

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Depending on what your doing, it may be better to resize the iframe according to it's contents with an iframe onLoad event.
See link:
1) add id attributes to your iframe and two input text elements.
2) don't use the old type width and height attributes - but instead use the style.width and style.height like in this example
3) seriously consider using jquery - it makes every javascript programmers life SO much easier (haven't used it in this example)
     ( jQuery: The Write Less, Do More, JavaScript Library )

    <script type="text/javascript">
        function $(elem) {
            return (document.getElementById(elem));
        function resize(elem, viewWidth, viewHeight) {
            var newWidth = $(viewWidth).value;
            var newHeight = $(viewHeight).value;
            var e = $(elem);
   = newWidth;
   = newHeight;
<form action="#" method="post" target="virtualDisplay" onsubmit="return false;">
Width : <input id="viewWidth" type="text" name="viewWidth" value="1024" /> x 
Height: <input id="viewHeight" type="text" name="viewHeight" value="800" />
<button type="submit" onclick="resize( 'virtualDisplay' , 'viewWidth' , 'viewHeight' )">try me.</button>
<iframe src ="" id="virtualDisplay" name="virtualDisplay">

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Please assign points or close this. If you need more help please state so or Request Attention on this. Thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.