Javascript function to replace large select statements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Richter
    New Member
    • May 2010
    • 3

    Javascript function to replace large select statements

    Hello all,

    I've got a Select that appears 32 times in a single form to choose one of 25 options. I'm looking to replace:

    Code:
    <select name="name">
      <option selected value="1"></option>
      <option value="2"></option>
    .
    .
    .
      <option  value="25"></option>
    </select>

    with a function call to generate the a drop-down list eliminating pages and pages of identical crap which takes some time to load. I think onFocus() could call this notional function, but have no idea how to return the value to an INPUT tag or similar. I'm leaning toward a text file that get populated by the form on page load, and the value changed by choosing an element from the function's pop up or pull down control.

    Yike. I'm an internals guy hacking Web code. Scary. :-)

    Thanks!

    -G
    Last edited by Dormilich; May 17 '10, 06:28 AM. Reason: Please use [code] tags when posting code
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    I’m not sure, whether the selects are responsible for the loading time … anyway, if that were indeed the case, loading a select via JavaScript would take even longer than loading via HTML. besides that your page would be useless without JS enabled. you could of course employ a server script to do the writing for you, though.

    regarding the value passing, before you kill the <select>, save its value and assign that value to the <input> you replace it with.

    Comment

    • Greg Richter
      New Member
      • May 2010
      • 3

      #3
      Well, no ... There is no server side available -- it's running on an FPGA and resources are very, very limited.

      The select works fine, but 27 lines of code, pasted 32 times takes a while to load. Like I said, it's a tiny device with a Web interface and is s-l-o-w.

      I figure calling a function and having that code appear once would be faster by quite a lot.

      The mechanization I'm trying to understand is that of a pull-out menu. If you mouseover a pull-out menu in Jscript, it slides out and offers you choices. You can then pick one, and motor along. Changing the event to onFocus instead of mouseover gets me where I need to be -- a popup control that takes user input.

      Question is how to implement that simply. I see a lot of bloated code, and I'm trying to avoid spending a week learning Jscript for one little hack. May have to do it, though. Hope not!

      Thanks, all ...

      Any thoughts?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        if you can auto-generate the content, then JavaScript may indeed be faster*, but it also depends on how fast JS runs on your device.

        rule of thumb—the better it looks, the more code you require.

        * - it doesn’t matter whether the dropdown code comes from the HTML source or from JS, the time you need to display/create it, should be similar. the question is, is it faster to download the HTML source, or the JS source & data.

        Comment

        • Greg Richter
          New Member
          • May 2010
          • 3

          #5
          You're precisely right of course ... It appears the best way to do this is via CSS, in fact. Sigh. I'm so not a Web guy.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            It’s hard for me to judge your system, there are so many dependencies, that I can’t tell, which is the fastes way.

            Comment

            Working...