Click here to Skip to main content
Sign Up to vote bad
good
See more: C#JavascriptHTML
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:24
Edited 10 Oct '12 - 19:51


2 solutions

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  
Your solution here. (C#)
 
Hope this helps.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 508
1 Arun Vasu 275
2 Maciej Los 238
3 OriginalGriff 215
4 Mahesh Bailwal 200
0 Sergey Alexandrovich Kryukov 9,660
1 OriginalGriff 7,329
2 CPallini 3,968
3 Rohan Leuva 3,339
4 Maciej Los 2,851


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid