Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Tuning question: JavaScript to generate options inside select

Tuning question: JavaScript to generate options inside select

Scheduled Pinned Locked Moved Web Development
questionjavascriptsysadmindata-structureshelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephan Pilz
    wrote on last edited by
    #1

    Hello togetherm I have a self written AJAX-Combobox and I have a tuning problem inside javascript. I get many records from server and will fill a client side combobox (select element) with all records like this:

    for (var i = 0; i < length; i++) {
    	oSel.options[i] = new Option (arrT[i], arrV[i], false, false);
    }
    

    This takes 30 seconds for 3600 array elements (-> 3600 options will be created). Have anybody an idea, how I can create the options very very faster? Thank you very much Stephan

                   \\\\\\|///
                 \\\\  - -  //
                  (  @ @  )
    

    +---------------oOOo-(_)-oOOo-----------------+
    | Stephan Pilz stephan.pilz@stephan-pilz.de |
    | www.stephan-pilz.de |
    | ICQ#: 127823481 |
    +-----------------------Oooo------------------+
    oooO ( )
    ( ) ) /
    \ ( (_/
    \_)

    M S 2 Replies Last reply
    0
    • S Stephan Pilz

      Hello togetherm I have a self written AJAX-Combobox and I have a tuning problem inside javascript. I get many records from server and will fill a client side combobox (select element) with all records like this:

      for (var i = 0; i < length; i++) {
      	oSel.options[i] = new Option (arrT[i], arrV[i], false, false);
      }
      

      This takes 30 seconds for 3600 array elements (-> 3600 options will be created). Have anybody an idea, how I can create the options very very faster? Thank you very much Stephan

                     \\\\\\|///
                   \\\\  - -  //
                    (  @ @  )
      

      +---------------oOOo-(_)-oOOo-----------------+
      | Stephan Pilz stephan.pilz@stephan-pilz.de |
      | www.stephan-pilz.de |
      | ICQ#: 127823481 |
      +-----------------------Oooo------------------+
      oooO ( )
      ( ) ) /
      \ ( (_/
      \_)

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      Just an idea. (not so sure whether it will work with your self-written Ajax-combobox). What about loading the data on demand? Like Microsoft Live Search result or dzone search result. In your case, it will be in your combobox instead of a page. You have 3600 records in the database, right? firstly, you can load a few records (50 or 100 records) and add them to your combobox. then, when the user scroll down then you can load the more records on demand...

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

      S 1 Reply Last reply
      0
      • M Michael Sync

        Just an idea. (not so sure whether it will work with your self-written Ajax-combobox). What about loading the data on demand? Like Microsoft Live Search result or dzone search result. In your case, it will be in your combobox instead of a page. You have 3600 records in the database, right? firstly, you can load a few records (50 or 100 records) and add them to your combobox. then, when the user scroll down then you can load the more records on demand...

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

        S Offline
        S Offline
        Stephan Pilz
        wrote on last edited by
        #3

        Yes. But (sorry for my stupid answer) I have no time to implement it. Have only time to make the line inside the loop faster. Stephan

                       \\\\\\|///
                     \\\\  - -  //
                      (  @ @  )
        

        +---------------oOOo-(_)-oOOo-----------------+
        | Stephan Pilz stephan.pilz@stephan-pilz.de |
        | www.stephan-pilz.de |
        | ICQ#: 127823481 |
        +-----------------------Oooo------------------+
        oooO ( )
        ( ) ) /
        \ ( (_/
        \_)

        M 1 Reply Last reply
        0
        • S Stephan Pilz

          Yes. But (sorry for my stupid answer) I have no time to implement it. Have only time to make the line inside the loop faster. Stephan

                         \\\\\\|///
                       \\\\  - -  //
                        (  @ @  )
          

          +---------------oOOo-(_)-oOOo-----------------+
          | Stephan Pilz stephan.pilz@stephan-pilz.de |
          | www.stephan-pilz.de |
          | ICQ#: 127823481 |
          +-----------------------Oooo------------------+
          oooO ( )
          ( ) ) /
          \ ( (_/
          \_)

          M Offline
          M Offline
          Michael Sync
          wrote on last edited by
          #4

          Stephan Pilz wrote:

          Have only time to make the line inside the loop faster

          Okay. All the best!

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

          1 Reply Last reply
          0
          • S Stephan Pilz

            Hello togetherm I have a self written AJAX-Combobox and I have a tuning problem inside javascript. I get many records from server and will fill a client side combobox (select element) with all records like this:

            for (var i = 0; i < length; i++) {
            	oSel.options[i] = new Option (arrT[i], arrV[i], false, false);
            }
            

            This takes 30 seconds for 3600 array elements (-> 3600 options will be created). Have anybody an idea, how I can create the options very very faster? Thank you very much Stephan

                           \\\\\\|///
                         \\\\  - -  //
                          (  @ @  )
            

            +---------------oOOo-(_)-oOOo-----------------+
            | Stephan Pilz stephan.pilz@stephan-pilz.de |
            | www.stephan-pilz.de |
            | ICQ#: 127823481 |
            +-----------------------Oooo------------------+
            oooO ( )
            ( ) ) /
            \ ( (_/
            \_)

            S Offline
            S Offline
            Shog9 0
            wrote on last edited by
            #5

            As Michael suggested, your best bet is to find a way of putting fewer items in the list. Not only will that speed up the routine, but you may actually find that your end-user is able to find items in the list more quickly as well... Otherwise, try building the HTML for the options in-memory and blasting it all out at once by assigning it to oSel.innerHTML. Might be a little faster, depending on the browser in use.

            M 1 Reply Last reply
            0
            • S Shog9 0

              As Michael suggested, your best bet is to find a way of putting fewer items in the list. Not only will that speed up the routine, but you may actually find that your end-user is able to find items in the list more quickly as well... Otherwise, try building the HTML for the options in-memory and blasting it all out at once by assigning it to oSel.innerHTML. Might be a little faster, depending on the browser in use.

              M Offline
              M Offline
              Michael Sync
              wrote on last edited by
              #6

              Shog9 wrote:

              try building the HTML for the options in-memory and blasting it all out at once by assigning it to oSel.innerHTML. Might be a little faster, depending on the browser in use

              Yeah. I think this is good idea too..

              Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups