Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

rjbs (4671)

rjbs
  (email not shown publicly)
http://rjbs.manxome.org/
AOL IM: RicardoJBSignes (Add Buddy, Send Message)
Yahoo! ID: RicardoSignes (Add User, Send Message)

I'm a Perl coder living in Bethlehem, PA and working Philadelphia. I'm a philosopher and theologan by training, but I was shocked to learn upon my graduation that these skills don't have many associated careers. Now I write code.

Journal of rjbs (4671)

Monday August 30, 2004
03:06 PM

my love/hate relationship with javascript

[ #20640 ]

Last week, I got TT2, CGI::Application, Class::DBI, and Number::Tolerant all engaging in wonderful harmony. It turned out, by the way, that I didn't need any kind of magic trigger to catch strings and convert them before they hit the database. It's more like this: my class has some fields that are inflated into tolerance objects. I can assign tolerances to them, and their stringification is stored to the database. When Class::DBI finds that stringification, it knows how to turn it back into an object. The beauty is that I can just assign a stringification directly. When I access it, I get the "inflated" version back. I had thought I needed to inflate it before assigning, but I was wrong. All I needed to to, to preserve my sanity, was to put a constraint on the column that only tolerances, valid strings, and undef were allowed to be set.

That's not today's accomplishment, though, it's last week's.

Today, I was just polishing off the main input form for this application. I'm hoping to have the delivery meeting tomorrow. Basically all of the fields are either free text, numbers, or tolerances. A number of the text fields should be multiple choice, but in all cases those multiple choices are just guidelines, and users may need to enter one-off values. This is a stupidly common scenario, and is the reason that combo boxes exist.

Of course, they don't exist in HTML forms. I suppose that since I've gotten through ten years of HTML authoring without really hitting this wall, it's not as big a need as I thought, but it's still pretty obnoxious. All the JavaScript combo boxes I found out on the web stank. Most of them were text fields with dropdowns next to them. Picking from the dropdown sets the text field. Ugly! I know I could've done some kind of crazy box-drawing to simulate a full combo box, but I can't stand the look of box-drawn widgets. They remind me that things are a hack. So, I wrote my own little combo box.

It's nothing fancy. There's a dropdown box with an "(other)" selection. When that's selected, the box replaces itself with a text-entry field. If that field is left blank, the dropdown comes back. It works on MSIE, it works in Gecko, it works with WebKit, and it plugs nicely into my goofy "make a select element" code at work.

So, that's great!

I hesitate to admit that this took hours, mostly because MSIE is completely messed up. Everything worked everywhere but Win32 MSIE, and I had to rewrite quite a lot of code to make it work, adding something like 400 bytes to the script. (That's about 30% growth.) Mostly, I had problems because setAttribute didn't seem to want to set the "name" attribute on form inputs. I'm told it works, but it didn't work for me. Assigning to the "name" attribute directly, though, works just fine.

So, that done and plugged into the application, I'm finished with work for the day. Have a free combo box:

        http://rjbs.manxome.org/hacks/js/combo.html

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I can't get it to work in Firefox 0.92/Win32, but it does work both in MSIE5.5 and 6.0. I've not yet checked out why, it just doesn't do anything, not even produce a Javascript error.
  • Also does nothing in Subject! And JavaScript was invented by the old Netscape folks wasn't it?

    I've spent way too much time trying to work JavaScript cross-browser compatibility. However, did notice the other day when I converted a MS Excel spreadsheet to HTML, that it was all written in JavaScript (albeit, the MS "version")! That was a nice touch!
    --
    Not knowing what to do, they do what they know . . .
  • Well, this is most distressing! There's another file in there... combo_old.html, I think. It worked everywhere but MSIE. I'll have to figure out what's going on in the Mozilla browsers. A quick play with the JS Console found nothing! I'll get Venkman on the case.

    Patches welcome.
    --
    rjbs
    • <html>

      <form id='form'>
          <select id='line_dropdown' name='line' onChange='conditional_toggle(this)'>
              <option value=''>(undefined)</option>
          <option value='10'>ten</option>
          <option value='20'>twenty</option>
          <option value='30'>thirty</option>

          <option value='!-@-!'>(other)</option>
          </select>
          <input type="tex

      • I'd rather make the new one work in firefox than the old one in MSIE! What's the issue here? Is it the use of a non-standard attribute?

        Also, because you're hiding the field and not removing it, it will submit its value, making the form processing logic uglier. It has to be removed or disabled (in WebKit, only the latter will work) to keep it from being submitted.
        --
        rjbs
        • I was thinking the backend would recieve the same data if it were a multi-select, so it would not get too ugly. On the other hand disabling it would be easy, element.disable = true; Adding and removing elements from the dom has always been a cross browser pain.
  • Rather than check for the comboToggle attribute, I just check for a special value, now. That seems to have been Mozilla's issue. I'll talk to some moz people sometime, but for now it now works everywhere. URL is the same.
    --
    rjbs
  • Opera 7.25 on a Sharp Zaurus SL6000L (Linux) didn't like it much either, Monday night.

    I'll try to remember to try again tonight since I see a "fixed for mozilla" reply.

    If it works and is portable it'll be a boon to webkind (even if it has the sad sideeffect of my having to enable Javascript on more sites because it's actully usefull not just spyware/adware).

    bill
    --
    Bill
    # I had a sig when sigs were cool
    use Sig;
    • Wednesday night, same result. Opera 7.25 on Z6k, window close when I click (other).

      posted thumb typing on the Z so I won~t forget

      bill
      --
      Bill
      # I had a sig when sigs were cool
      use Sig;