Click here to Skip to main content
15,880,427 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have two divs I want to set the width dynamically to the size of the gridViews. I have tried two ways, bit new with javascript. I get error that states 'setWidths' is not a member of *.aspx. My requirements are to center the GridViews which I have tried with css(.Middle{margin-left:auto;margin-right:auto;position:relative;}) which does not work - however the div element does respond to this as long as it has a width defined.

XML
<script language="javascript" type="text/javascript" >
       function setWidths() {
       $('divME').width = $('gvME').width;
       $('divDE').width = $('gvDE').width;
       return;}
   </script>


divME.Attributes("Width") = someValue

What am I missing?
Posted
Updated 24-Jan-13 11:16am
v2
Comments
Idle_Force 24-Jan-13 16:40pm    
I will try those suggestions, but my first problem its not recognizing the javascript function name

Your selectors do not look right. You would need to do something like $('#divME') for div. Does your grid stay on a page that has a master page? if so the id selector will be different. Therefore you could do $('id$="gvME"').

With that, you are also probably after the width with units. the ".width" will only return the number without units so this may not work.

try something like (not tested and im not javascript expert but...):

$('#divME').css.width($('id$="gvME"').css.width());

http://api.jquery.com/width/[^]
 
Share this answer
 
First problem I can see is: jQuery selectors are wrong. You are using the syntax of element selectors but there are no such elements as "divME", "divDE", etc. Did you mean "#divME" (id) or something else? Please see to fix it:
http://api.jquery.com/category/selectors/[^].

Also I would advise to use more complex layout and CSS instead of JavaScript. Then the width will be adjusted without any scripting. You need to read about CSS box model and related topics. As I don't know your layout requirements, I cannot help you in more detail at this moment.

—SA
 
Share this answer
 
v2
Comments
Idle_Force 24-Jan-13 17:16pm    
Updated!
Idle_Force 24-Jan-13 17:28pm    
Can you tell me why my javascript is not recognised?
Sergey Alexandrovich Kryukov 24-Jan-13 17:32pm    
What is update, where and how, and why do you think I need to know about it?
What do you mean by "not recognized"?
Can you use JavaScript debugger to see what's going on?
—SA
Idle_Force 24-Jan-13 19:17pm    
Updated info - cause most here appreciate when we supply more info??? When I type in the name of the javascript function in the OnClick of a button, example, I get an error saying it does not exist on the page during runtime. I have followed some examples from w3schools with intermittent luck.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900