<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

	<title>Comments on: Tricks Involving Concatenation and Pull-Down Menus for HTML Forms?</title>
	<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms/</link>
	<description>Comments on Ask MetaFilter post Tricks Involving Concatenation and Pull-Down Menus for HTML Forms?</description>
	<pubDate>Thu, 12 Jul 2007 09:52:33 -0800</pubDate>
	<lastBuildDate>Thu, 12 Jul 2007 09:52:33 -0800</lastBuildDate>
	<language>en-us</language>
	<docs>http://blogs.law.harvard.edu/tech/rss</docs>
	<ttl>60</ttl>

	<item>
		<title>Question: Tricks Involving Concatenation and Pull-Down Menus for HTML Forms?</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms</link>	
		<description>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. &lt;br /&gt;&lt;br /&gt; 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?&lt;br&gt;
&lt;br&gt;
I have a personal HTML form I use.  It&apos;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 &apos;Household&apos;, meaning &apos;to keep my household running&apos;), and a task list I want it to post to (in this case, a list also named &apos;Household&apos;).  This way, I don&apos;t forget to include a value, nor do I have to remember what my choices are.  I don&apos;t think I could use the site without this revised form -- I&apos;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).&lt;br&gt;
&lt;br&gt;
I have two ideas I&apos;d like to implement in order to improve its efficiency, but they&apos;re beyond my HTML ken.&lt;br&gt;
&lt;br&gt;
First, as things stand now, I have to manually concatenate the goal and locale tags.  I tab to a &quot;Concatenate&quot; button and hit it, and it concatenates the locale and goal choices I&apos;ve made in those menus into the &quot;tags&quot; field.  The HTML I use for this is:&lt;br&gt;
&lt;br&gt;
[input type=&quot;button&quot; tabindex=&quot;5&quot; value=&quot;Concatenate&quot; onClick=&quot; document.all.tags.value = document.all.locale.value + &apos; &apos; + document.all.goal.value;&quot;]&lt;br&gt;
&lt;br&gt;
What I&apos;m wondering is, is there a way I can have the system concatenate the &apos;locale&apos; and &apos;goal&apos; values into the &apos;tags&apos; tag field automatically, without a need for the &quot;onClick&quot; event?  And would this way reflect any changes made to those values?&lt;br&gt;
&lt;br&gt;
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&apos;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 &apos;goal&apos; value (say, the string &apos;g-Household&apos;) and the &apos;list&apos; value it should go to (takes the form of a list ID, so it might be &apos;04123123,&apos; which, let&apos;s say, corresponds to the Household task list).  Can this be done?  As it stands, the choice of individual &quot;[option]s&quot; just fill in one variable.&lt;br&gt;
&lt;br&gt;
Thanks, guys!</description>
		<guid isPermaLink="false">post:ask.metafilter.com,2007:site.66824</guid>
		<pubDate>Thu, 12 Jul 2007 09:39:30 -0800</pubDate>
		<dc:creator>WCityMike</dc:creator>
		
			<category>HTML</category>
		
			<category>javascript</category>
		
			<category>forms</category>
		
			<category>resolved</category>
		
	</item> <item>
		<title>By: boo_radley</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002186</link>	
		<description>You say you&apos;ve got two fields that need to be concatenated. I assume these are text fields for my example.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
you can move your onClick code to one or both of your text fields:&lt;br&gt;
&lt;code&gt; &lt;br&gt;
  &amp;lt;input type=&quot;text&quot; id=&quot;locale&quot; name=&quot;locale&quot; onkeypress=&quot;document.all.tags.value = document.all.locale.value + &apos; &apos; + document.all.goal.value;&quot;&amp;gt;&lt;br&gt;
&lt;br&gt;
  &amp;lt;input type=&quot;text&quot; id=&quot;locale&quot; name=&quot;goal&quot; onkeypress=&quot;document.all.tags.value = document.all.locale.value + &apos; &apos; + document.all.goal.value;&quot;&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
for your second question: would it be feasible to simple remove one of the menus?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002186</guid>
		<pubDate>Thu, 12 Jul 2007 09:52:33 -0800</pubDate>
		<dc:creator>boo_radley</dc:creator>
	</item><item>
		<title>By: WCityMike</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002193</link>	
		<description>Boo_radley, thanks, I shall give that a try.&lt;br&gt;
&lt;br&gt;
Re: the pulldown menus, the goal definitely is to remove one of the menus, but I need to have one menu choice define two variables.  Since I&apos;m sending these variables to Remember the Milk, I don&apos;t have any ability to change the values needed for the task.&lt;br&gt;
&lt;br&gt;
Essentially, I&apos;d like the pull-down menu to be smart enough to say:&lt;br&gt;
&lt;br&gt;
* Household (if chosen, populate goal value with &quot;household&quot; and list ID value with &quot;8675309&quot;)&lt;br&gt;
* Car (if chosen, populate goal value with &quot;car&quot; and list ID value with &quot;24601&quot;)&lt;br&gt;
* and so on ...</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002193</guid>
		<pubDate>Thu, 12 Jul 2007 09:59:12 -0800</pubDate>
		<dc:creator>WCityMike</dc:creator>
	</item><item>
		<title>By: WCityMike</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002197</link>	
		<description>Actually, I&quot;m sorry, boo_radley, the locale and goal fields are actually select fields:&lt;br&gt;
&lt;br&gt;
[select name=&quot;locale&quot; id=&quot;locale&quot; size=6 tabindex=&quot;2&quot;]&lt;br&gt;
&lt;br&gt;
Would the &apos;onkeypress&apos; still work there?  I&apos;m usually either tabbing to the field and using arrow keys, or mouse-clicking.  If not, is there an alternate means?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002197</guid>
		<pubDate>Thu, 12 Jul 2007 10:01:11 -0800</pubDate>
		<dc:creator>WCityMike</dc:creator>
	</item><item>
		<title>By: boo_radley</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002232</link>	
		<description>yep, it should still work ok in a select field; it&apos;s got all the events you need. Also, your select&apos;s options can have values as well as text:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
  &amp;lt;select&amp;gt;&lt;br&gt;
    &amp;lt;option value=&apos;8675309&apos;&amp;gt;household&amp;amp;lt/option&amp;gt;&lt;br&gt;
    &amp;lt;option value=&apos;24601&apos;&amp;gt;car&amp;amp;lt/option&amp;gt;&lt;br&gt;
  &amp;lt;select&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
That way you can do&lt;br&gt;
&lt;code&gt;&lt;br&gt;
  var idx = document.getElementById(&quot;locale&quot;).selectedIndex&lt;br&gt;
  var text = document.getElementById(&quot;locale&quot;).options[idx]&lt;br&gt;
  var code = document.getElementById(&quot;locale&quot;).value&lt;br&gt;
&lt;/code&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002232</guid>
		<pubDate>Thu, 12 Jul 2007 10:31:43 -0800</pubDate>
		<dc:creator>boo_radley</dc:creator>
	</item><item>
		<title>By: WCityMike</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002234</link>	
		<description>Hmmm.  That may be it!  Let me go scurry off and go a-tweakin&apos; now. :)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002234</guid>
		<pubDate>Thu, 12 Jul 2007 10:33:10 -0800</pubDate>
		<dc:creator>WCityMike</dc:creator>
	</item><item>
		<title>By: WCityMike</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002252</link>	
		<description>With regard to the first question (tackling the questions one at a time), it appears not to be working with selects looking like this:&lt;br&gt;
&lt;br&gt;
&amp;lt;select name=&quot;g&quot; id=&quot;g&quot; size=8 tabindex=&quot;3&quot; onkeypress=&quot;document.all.tx.value = document.all.locale.value + &apos; &apos; + document.all.g.value;&quot;&amp;gt;&lt;br&gt;
&lt;br&gt;
Anything I&apos;m doing wrong?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002252</guid>
		<pubDate>Thu, 12 Jul 2007 10:43:26 -0800</pubDate>
		<dc:creator>WCityMike</dc:creator>
	</item><item>
		<title>By: WCityMike</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002262</link>	
		<description>Actually, if I duplicate the same statement with an onClick, that seems to take care of it:&lt;br&gt;
&lt;br&gt;
&amp;lt;select name=&quot;g&quot; id=&quot;g&quot; size=8 tabindex=&quot;3&quot; onkeypress=&quot;document.all.tx.value = document.all.locale.value + &apos; &apos; + document.all.g.value;&quot; onClick=&quot;document.all.tx.value = document.all.locale.value + &apos; &apos; + document.all.g.value;&quot;&amp;gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002262</guid>
		<pubDate>Thu, 12 Jul 2007 10:49:24 -0800</pubDate>
		<dc:creator>WCityMike</dc:creator>
	</item><item>
		<title>By: Artful Codger</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002283</link>	
		<description>In your select tag, &lt;br&gt;
- I don&apos;t think onkeypress is the best event to use. Use onChange or the click or the focus - whatever&apos;s the desired interaction.&lt;br&gt;
&lt;br&gt;
- the select itself doesn&apos;t have a value, it has a selected index, then you have to access the value of the selected option.&lt;br&gt;
&lt;br&gt;
Like so:&lt;br&gt;
&lt;br&gt;
&amp;lt;select name=&quot;g&quot; id=&quot;g&quot; size=8 tabindex=&quot;3&quot; onChange=&quot;document.forms[0].tx.value = document.forms[0].locale.value + &apos; &apos; + document.forms[0].g.  options[document.forms[0].g.selectedIndex].value;&quot;&amp;gt;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
I&apos;m not a big fan of document.all ..., to access form fields in javascript I mainly use document.forms[form index# or form name].fieldname.&lt;br&gt;
&lt;br&gt;
Anyway, my favourite js reference site is the Javascript FAQ at &lt;a href=&quot;http://irt.org/script/form.htm&quot;&gt;irt.org&lt;/a&gt;</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002283</guid>
		<pubDate>Thu, 12 Jul 2007 11:01:43 -0800</pubDate>
		<dc:creator>Artful Codger</dc:creator>
	</item><item>
		<title>By: mkultra</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002287</link>	
		<description>With SELECT elements, you need to use the &quot;onChange&quot; property. Accessing the value of the selected element is a bit trickier:&lt;br&gt;
&lt;br&gt;
document.getElementById(&apos;[ELEMENT_NAME]&apos;).options[document.getElementById(&apos;[ELEMENT_NAME]&apos;).selectedIndex].value&lt;br&gt;
&lt;br&gt;
So, you&apos;ll have:&lt;br&gt;
&lt;br&gt;
onSelect=&quot;document.getElementById(&apos;tx&apos;).value=document.getElementById(&apos;locale&apos;).options[document.getElementById(&apos;locale&apos;).selectedIndex].value + document.getElementById(&apos;g&apos;).options[document.getElementById(&apos;g&apos;).selectedIndex].value;&quot;&lt;br&gt;
&lt;br&gt;
Note that &quot;getElementById&quot; is the preferred (DOM-compliant?) method of accessing elements, not &quot;document.all.[ELEMENT_NAME]&quot;. You will need to specify the ID attribute of your drop-down menus as well as the NAME.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002287</guid>
		<pubDate>Thu, 12 Jul 2007 11:04:58 -0800</pubDate>
		<dc:creator>mkultra</dc:creator>
	</item><item>
		<title>By: mkultra</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002291</link>	
		<description>er, that&apos;s onChange=, not onSelect=</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002291</guid>
		<pubDate>Thu, 12 Jul 2007 11:06:33 -0800</pubDate>
		<dc:creator>mkultra</dc:creator>
	</item><item>
		<title>By: WCityMike</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002293</link>	
		<description>Hey, boo_radley, if you&apos;re still there, I&apos;ve run into a snag with the second of the two -- the tag problem.  Two problems.&lt;br&gt;
&lt;br&gt;
First, I can&apos;t seem to get the concatenation to work in concert with Javascript setting the g value from the list.  Where do I put those var statements?  I tried them both as a header and in the actual onkeypress and onClick events, and neither seemed to work; both seemed to destroy the ability to concatenate.&lt;br&gt;
&lt;br&gt;
The second problem is this: is there a way to actually assign a second value that isn&apos;t the text of the entry?  Reason I ask is this:&lt;br&gt;
&lt;br&gt;
&amp;lt;option value=&quot;730842&quot;&amp;gt;&amp;nbsp;&lt;br&gt;
&amp;lt;option value=&quot;1223729&quot;&amp;gt;@NONE&lt;br&gt;
&amp;lt;option value=&quot;1446561&quot;&amp;gt;g-Project1&lt;br&gt;
&amp;lt;option value=&quot;1223636&quot;&amp;gt;g-Project2&lt;br&gt;
&amp;lt;option value=&quot;1274826&quot;&amp;gt;g-Project3&lt;br&gt;
&amp;lt;option value=&quot;1223704&quot;&amp;gt;g-Project4&lt;br&gt;
&amp;lt;option value=&quot;1223664&quot;&amp;gt;g-Project5&lt;br&gt;
&amp;lt;option value=&quot;1256310&quot;&amp;gt;-SubProject1&lt;br&gt;
&amp;lt;option value=&quot;1274827&quot;&amp;gt;g-Project6&lt;br&gt;
&amp;lt;option value=&quot;1223704&quot;&amp;gt;g-Project7&lt;br&gt;
&amp;lt;option value=&quot;1274823&quot;&amp;gt;-SubProject1&lt;br&gt;
&amp;lt;option value=&quot;1275170&quot;&amp;gt;-SubProject2&lt;br&gt;
&amp;lt;option value=&quot;1274822&quot;&amp;gt;-SubProject3&lt;br&gt;
&amp;lt;option value=&quot;1243750&quot;&amp;gt;-SubProject4&lt;br&gt;
&lt;br&gt;
That&apos;s what my list looks like (well, privatized).  Now, the value is the list ID.  And the text is close to being a tag.  However, occasionally it&apos;s friendlier, and the subprojects screw things up, because I need them to be tagged with their project&apos;s tag&lt;br&gt;
&lt;br&gt;
&amp;lt;option value=&quot;730842&quot;&amp;gt;&amp;nbsp; (no tag)&lt;br&gt;
&amp;lt;option value=&quot;1223729&quot;&amp;gt;@NONE (no tag)&lt;br&gt;
&amp;lt;option value=&quot;1446561&quot;&amp;gt;g-Project1 (tag as g-project1)&lt;br&gt;
&amp;lt;option value=&quot;1223636&quot;&amp;gt;g-Project2 (tag as g-project2)&lt;br&gt;
&amp;lt;option value=&quot;1274826&quot;&amp;gt;g-Project3 (tag as g-project3)&lt;br&gt;
&amp;lt;option value=&quot;1223704&quot;&amp;gt;g-Project4 (tag as g-project4)&lt;br&gt;
&amp;lt;option value=&quot;1223664&quot;&amp;gt;g-Project5 (tag as g-project5)&lt;br&gt;
&amp;lt;option value=&quot;1256310&quot;&amp;gt;-SubProject1 (tag as g-project5)&lt;br&gt;
&amp;lt;option value=&quot;1274827&quot;&amp;gt;g-Project6 (tag as g-project6)&lt;br&gt;
&amp;lt;option value=&quot;1223704&quot;&amp;gt;g-Project7 (tag as g-project7)&lt;br&gt;
&amp;lt;option value=&quot;1274823&quot;&amp;gt;-SubProject1 (tag as g-project7)&lt;br&gt;
&amp;lt;option value=&quot;1275170&quot;&amp;gt;-SubProject2 (tag as g-project7)&lt;br&gt;
&amp;lt;option value=&quot;1274822&quot;&amp;gt;-SubProject3 (tag as g-project7)&lt;br&gt;
&amp;lt;option value=&quot;1243750&quot;&amp;gt;-SubProject4 (tag as g-project7)&lt;br&gt;
&lt;br&gt;
Is that feasible, or impossible?</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002293</guid>
		<pubDate>Thu, 12 Jul 2007 11:07:27 -0800</pubDate>
		<dc:creator>WCityMike</dc:creator>
	</item><item>
		<title>By: WCityMike</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002302</link>	
		<description>That &quot;Is that feasible, or impossible?&quot; line sounds a little demanding.  Didn&apos;t mean in that tone &amp;mdash; just wondering if I&apos;m asking for the moon. :)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002302</guid>
		<pubDate>Thu, 12 Jul 2007 11:13:00 -0800</pubDate>
		<dc:creator>WCityMike</dc:creator>
	</item><item>
		<title>By: boo_radley</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002365</link>	
		<description>Maybe you could drop me an email with your page. I&apos;d be happy to take a look at it.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002365</guid>
		<pubDate>Thu, 12 Jul 2007 12:05:32 -0800</pubDate>
		<dc:creator>boo_radley</dc:creator>
	</item><item>
		<title>By: WCityMike</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002423</link>	
		<description>By the way, didn&apos;t mean to ignore the rest of you -- I had the &quot;#comment&quot; bookmarked so it just jumped to the bottom of the page, so I missed your comments.  I actually implemented the onChange thing.&lt;br&gt;
&lt;br&gt;
Boo, I&apos;m sending you an e-mail with the URL.</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002423</guid>
		<pubDate>Thu, 12 Jul 2007 12:53:41 -0800</pubDate>
		<dc:creator>WCityMike</dc:creator>
	</item><item>
		<title>By: mkultra</title>
		<link>http://ask.metafilter.com/66824/Tricks-Involving-Concatenation-and-PullDown-Menus-for-HTML-Forms#1002441</link>	
		<description>&lt;i&gt;Where do I put those var statements?&lt;/i&gt;&lt;br&gt;
&lt;br&gt;
You would put them in a function that you call on your onChange(). If you put them in just by themselves, they&apos;re only ever run once, so those variables become fixed.&lt;br&gt;
&lt;br&gt;
Also, this:&lt;br&gt;
&lt;br&gt;
&lt;code&gt;&lt;br&gt;
var text = document.getElementById(&quot;locale&quot;).options[idx]&lt;br&gt;
var code = document.getElementById(&quot;locale&quot;).value&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
should be:&lt;br&gt;
&lt;code&gt;&lt;br&gt;
var text = document.getElementById(&quot;locale&quot;).options[idx].text;&lt;br&gt;
var code = document.getElementById(&quot;locale&quot;).options[idx].value;&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
Trust me, though- that one line of code I posted does everything you need :)</description>
		<guid isPermaLink="false">comment:ask.metafilter.com,2007:site.66824-1002441</guid>
		<pubDate>Thu, 12 Jul 2007 13:16:00 -0800</pubDate>
		<dc:creator>mkultra</dc:creator>
	</item>
	</channel>
</rss>
