Tricks Involving Concatenation and Pull-Down Menus for HTML Forms?
July 12, 2007 9:39 AM
Subscribe
If you are a HTML or Javascript kung-fu master, I need a sensei to advise me as to a few exotic tricks I desire to implement involving HTML form fields.
Is there Javascript or HTML trickery that will automatically concatenate contents of a field in an HTML form, and/or update that field if the choices are changed? Also, is there a way for a choice from an HTML pull-down menu to assign values to two variables, instead of just one?
I have a personal HTML form I use. It's essentially a rewrite of the Quick Add bookmarklet for Remember the Milk. However, with this personalized version, I choose from individual menus a locale (say, @work), a tag for the goal this task goes towards (say 'Household', meaning 'to keep my household running'), and a task list I want it to post to (in this case, a list also named 'Household'). This way, I don't forget to include a value, nor do I have to remember what my choices are. I don't think I could use the site without this revised form -- I've also whipped up little custom jobs for two kinds of specialized tasks I do (putting certain events on the task list, and adding a book to my reading list).
I have two ideas I'd like to implement in order to improve its efficiency, but they're beyond my HTML ken.
First, as things stand now, I have to manually concatenate the goal and locale tags. I tab to a "Concatenate" button and hit it, and it concatenates the locale and goal choices I've made in those menus into the "tags" field. The HTML I use for this is:
[input type="button" tabindex="5" value="Concatenate" onClick=" document.all.tags.value = document.all.locale.value + ' ' + document.all.goal.value;"]
What I'm wondering is, is there a way I can have the system concatenate the 'locale' and 'goal' values into the 'tags' tag field automatically, without a need for the "onClick" event? And would this way reflect any changes made to those values?
Second, as you might tell from the above example, in many cases, the list a task is going to, and the goal tag for a task, happen to be the same. I'd love to eliminate a menu from this step by having a choice from the HTML pull-down menu define BOTH a choice for the 'goal' value (say, the string 'g-Household') and the 'list' value it should go to (takes the form of a list ID, so it might be '04123123,' which, let's say, corresponds to the Household task list). Can this be done? As it stands, the choice of individual "[option]s" just fill in one variable.
Thanks, guys!
posted by WCityMike to computers & internet (15 comments total)
3 users marked this as a favorite
you can move your onClick code to one or both of your text fields:
<input type="text" id="locale" name="locale" onkeypress="document.all.tags.value = document.all.locale.value + ' ' + document.all.goal.value;">
<input type="text" id="locale" name="goal" onkeypress="document.all.tags.value = document.all.locale.value + ' ' + document.all.goal.value;">
for your second question: would it be feasible to simple remove one of the menus?
posted by boo_radley at 9:52 AM on July 12, 2007