views:

44

answers:

2

I have a Table (or a region) and want to set it's Width and Height value to another Div (or region).

The second one is actually a Ajax Indicator modal which display a loading text when the page is asynchronously post back. here is the example

<table id="MainTable">
    <tr>
        <td>
             Content ....
        </td>
    </tr>
</table>

<div id="Progress">
     Ajax Indocator
</div>

the following javascript didn't work

document.getElementById("Progress").style.width = document.getElementById("MainTable").style.width;
document.getElementById("Progress").style.height = document.getElementById("MainTable").style.height;

It should work both on IE and FireFox. how to correct it.

I checked some other solution in StackOverFlow but I couldn't fix it.

I'm waiting to hear from you.


Update : I use this

<script>
function SetSize(regionToChange, mainRegion) {
    $(document).ready(function() {
        $('#regionToChange)
 .width($('#mainRegion).outerWidth())
 .height($('#mainRegion).outerHeight());
    }); 
}
</script>

and I call it like

<asp:Button ID="btnReset" runat="server" SkinID="Button" Text="Reset" OnClick="btnReset_OnClick" OnClientClick="SetSize('Progress', 'MainTable');" />

But it shows me an error which can not find the object


Update 2 I see this error

alt text

and in debugger I face with this

alt text

+1  A: 

in jQuery you can do

$("#Progress").css('width', function(){
   return $("#MainTable").width()+'px';
});

and so with the height...

edit

on javascript,

this

document.getElementById("Progress").style.width = document.getElementById("MainTable").style.width;
document.getElementById("Progress").style.height = document.getElementById("MainTable").style.height;

will work if your html is something like this for id="MainTable"

<table id="MainTable" style="width: 500px; height: 300px;">
    <tr>
        <td>
             Content ....
        </td>
    </tr>
</table>

because you are accessing style attribute...

edit2

 function SetSize(regionToChange, mainRegion) {
        $(regionToChange)
         .width($(mainRegion).outerWidth())
         .height($(mainRegion).outerHeight());

  }

//you can use it as

SetSize('#Progress','#MainTable'); // prefix '#'if it's an ID 
Reigel
@Reigel - what about Javascript?
Nasser Hadjloo
please see edit...
Reigel
@Reigel - I used yours and it doesn't worked. I also update my question with query you mentioned but it shows an error. and it doesn't work. take a look please.
Nasser Hadjloo
please see edit2
Reigel
note that you must include http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js before using that...
Reigel
@Reigel - I've added Jquery `1.4.2 min` to my project and I face with the bug I mentioned in `Update 2`. you can see it in my question. Thank you in advance
Nasser Hadjloo
did you prefix a `#` and not something like this `OnClientClick="SetSize('Progress', 'MainTable');"` ?
Reigel
I'm disappointed (just a little)
jAndy
@jAndy hehe... he used your answer wrongly and ask me how to correct it.. ;)
Reigel
+1  A: 

spoken in jQuery:

$(document).ready(function(){
   $('#Progress')
     .width($('#MainTable').outerWidth())
     .height($('#MainTable').outerHeight());
});
jAndy
@jAndy- What about Javascript - And notethat this is a common method which will use in all pages of application so the IDs should be variable.
Nasser Hadjloo
Well, actually it IS javascript. If you are looking for cross-browser compatibility using a framework like jQuery is the best thing you can do.
jAndy
Check my update jAndy. I have a bug with this script
Nasser Hadjloo