Click here to Skip to main content
12,299,947 members (44,358 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Javascript HTML
I am not able to Increase dropdownlist width according to item length.
I am trying as like this..

<script type="text/javascript">
    function autoWidth()
    {
        var maxlength = 0;
        var mySelect = document.getElementById('Select1');
        for (var i=0; i<mySelect.options.length;i++)
        {
            if (mySelect[i].text.length > maxlength)
            {
                maxlength = mySelect[i].text.length;
            }
        }
        mySelect.style.width = maxlength * 10;
    }
</script>


but it is not working in mozila. Please help me...
Posted 9-Oct-12 23:24pm
Edited 10-Oct-12 19:51pm
v4
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Try this

<script type="text/javascript">
    function autoWidth()
    {
        var maxlength = 0;
        var mySelect = document.getElementById('Select1');
        for (var i=0; i<mySelect.options.length;i++)
        {
            if (mySelect[i].text.length > maxlength)
            {
                maxlength = mySelect[i].text.length;
            }
        }
        mySelect.style.width = maxlength * 10;
    }
</script>
And use it like this: onclick="autoWidth()"
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Your solution here. (C#)

Hope this helps.
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160525.2 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100