• Home
  • About Jon Dowdle
  • Lifestream
  • Code from TDD Demystified through Kat...
    Passing

    A big thanks to everyone that came out for today's CFMeetup. The code is located here and the presentation is located here. While practicing for this presentation, I noticed [...]

    Read more
KEEP IN TOUCH

Integrating freeform <select> with JavaScript and CSS

Mar12
2007
Written by Jon Dowdle

At work I have an application that requires a user to select a choice from a drop down box or a <select> control for the HTML savvy. As far as I know (or could find) there is no such control in HTML 4.01 that allows both a select box with the added bonus of taking free form user input. So to meet the needs of this project I crafted one up using CSS and JavaScript. This is my first dive into CSS/JS in a while so be gentle.

I accomplished this by creating two elements (SELECT & INPUT) and then switching the elements visibility properties.

<script type="text/javascript" >
function showOther(id, id2){
  if(id.options[id.selectedIndex].label == "Other"){
   id.style.visibility = "hidden";
   id2.style.visibility = "visible";
  }
}
</script>
<select id="sel1" onChange="showOther(sel1, inp1)"
style="position:absolute; left:10; top:10;" >
  <option value="0" label=""></option>
  <option value="1" label="Choice1">Choice1</option>
  <option value="2" label="Choice2">Choice2</option>
  <option value="3" label="Other">Other</option>
</select>
<input type="text" id="inp1" style="visibility='hidden'"
style="position:absolute; left:10; top:10;" />

To see it in action go here

Posted in Code, Programming, Web Design, Work - Tagged html, javascript
SHARE THIS Twitter Facebook Delicious StumbleUpon E-mail
« Anti-DRM Video
» Vim: Seven habits of effective text editing

5 Comments

  1. todd's Gravatar todd
    March 13, 2007 at 2:11 pm | Permalink

    What you want is an auto-completion script…

    e.g. like this:
    http://www.google.com/webhp?complete=1&hl=en

    where you start with a text box, but typing something, presents the potential matching items…

  2. jon's Gravatar jon
    March 14, 2007 at 12:31 am | Permalink

    Yeah I do like that feature as well. For the application in which that came from, that input was for medicine names (for Dr use) so we thought the list of choices would be the best. But thanks for the link. Much appreciated.

  3. Will Thompson's Gravatar Will Thompson
    March 14, 2007 at 1:29 pm | Permalink

    Hrm, but now if you accidentally choose “other” you’re stuck.

  4. jon's Gravatar jon
    March 14, 2007 at 1:46 pm | Permalink

    @ Will
    Yup.
    I’ve since changed the code to include ondblclick within the input box.
    Now when the user double clicks in the input box the select will once again be visible.

    I plan on taking that a step further so it is a little more intuitive. I should post it within the week.

  5. Wahoo's Gravatar Wahoo
    October 6, 2007 at 4:37 pm | Permalink

    Thank you for sharing!

Recent Posts

  • Code from TDD Demystified through Katas
  • Awesome Web Development Links Found This Week
  • Taggable Demo Video (now with more code)
  • Taggable Demo Video
  • New jQuery Plugin: Taggable

Categories

  • Code
    • MySQL
    • Programming
    • Web Design
  • coldfusion
  • Life
    • Events
  • Reviews
  • Uncategorized
  • Work

Tags

adobe barcamp barcamporlando coldfusion ComplexByteArrayException concat conferences decorator design pattern Events firebug Form fowa html IE ignite infection control iterator javascript job jQuery movies MySql orlando Photos pirate booty pirates plugins poll project python railo software development sql stackoverflow stax.net style taggable tags talk like a pirate tips & tricks tools twitter washington dc Web Design

RSS Syndication

  • All posts
  • All comments

EvoLve theme by Theme4Press  •  Powered by WordPress jDowdle.com