Hi list, I have a list of tags. I want to be able to click on a tag and have that tag name populate an input field. I think delicious used to allow you to click on existing links to tag your bookmark similar to this (moving instead to auto_complete). My guess is the code looks something like this.... <form> <input type="text" name="all" id="discover" size="16" value="test1, test2"/> </form> <a href onClick="document.form.discover.value == ''test3, test4''">click me</a> ...but I can''t get it to work. Any suggestions? Thanks, Steve http://www.smarkets.net -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060331/77405e1c/attachment.html
Steve Odom wrote:> Hi list, > > I have a list of tags. I want to be able to click on a tag and have that > tag > name populate an input field. I think delicious used to allow you to > click > on existing links to tag your bookmark similar to this (moving instead > to > auto_complete). > > My guess is the code looks something like this.... > <form> > <input type="text" name="all" id="discover" size="16" value="test1, > test2"/> > </form> > > <a href onClick="document.form.discover.value == ''test3, test4''">click > me</a> > > ...but I can''t get it to work. Any suggestions? > > Thanks, > > Steve > http://www.smarkets.netYou need to use document.forms[0].discover.value = ''test3, test4'' if you want it to work with XHTML (to be validated XHTML) use this: # In the head of the page <script type="text/javascript"> function oload() { if (document.getElementsByTag) { anchs = document.getElementsByTag("a"); for (i = 0; i < anchs.length; i++) { if (anchs[i].rel == "fillform") { anchs[i].onclick = document.forms[0].discover.value = "test3, test4"; } } } else { return false; } } window.onload = oload; </script> # In the body of the page <form> <input type="text" name="all" id="discover" size="16" value="test1, test2" /> </form> <a href="#" rel="fillform">click me</a> This should work! Have fun ;) -- Posted via http://www.ruby-forum.com/.
Well, first of all, the button should be between the <form> ... </form> tags (it should work even if not, but lets just be strictly correct). Your form needs a name, for example <form name="form1">. Then its'' onClick="document.form1.discover.value = test3, test4" Notice only one equals, not two? That should sort it out. Hope that''s helped. -N On 31/03/06, Steve Odom <steve.odom@gmail.com> wrote:> Hi list, > > I have a list of tags. I want to be able to click on a tag and have that tag > name populate an input field. I think delicious used to allow you to click > on existing links to tag your bookmark similar to this (moving instead to > auto_complete). > > My guess is the code looks something like this.... > <form> > <input type="text" name="all" id="discover" size="16" value="test1, test2"/> > </form> > > <a href onClick="document.form.discover.value == ''test3, test4''">click > me</a> > > ...but I can''t get it to work. Any suggestions? > > Thanks, > > Steve > http://www.smarkets.net > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Thanks to both of you for the help. Your comments helped steer me in the right direction. I''m using the behaviour.js library so has allowed me to simplify it somewhat. Here is my js: ''.tag_link'' : function(el){ el.onclick = function(){ var str = document.tag_form.discover.value + ", " + el.rel document.tag_form.discover.value = str; } }, And my form: <form name="tag_form"> <input type="text" name="all" id="discover" size="16" value="test1, test2"/> <a href="#" rel="mytag1" class="tag_link">click me</a><br /> <a href="#" rel="mytag2" class="tag_link">click me</a><br /> <a href="#" rel="mytag3" class="tag_link">click me</a><br /> </form> It validates (except for not having an action in the form tag, which I''ll add in a bit. Does anyone see any problems with this? Seems to work fine. Steve http://www.smarkets.net On 3/31/06, njmacinnes@gmail.com <njmacinnes@gmail.com> wrote:> > Well, first of all, the button should be between the <form> ... > </form> tags (it should work even if not, but lets just be strictly > correct). > Your form needs a name, for example <form name="form1">. Then its'' > onClick="document.form1.discover.value = test3, test4" Notice only one > equals, not two? That should sort it out. Hope that''s helped. > -N > > On 31/03/06, Steve Odom <steve.odom@gmail.com> wrote: > > Hi list, > > > > I have a list of tags. I want to be able to click on a tag and have that > tag > > name populate an input field. I think delicious used to allow you to > click > > on existing links to tag your bookmark similar to this (moving instead > to > > auto_complete). > > > > My guess is the code looks something like this.... > > <form> > > <input type="text" name="all" id="discover" size="16" value="test1, > test2"/> > > </form> > > > > <a href onClick="document.form.discover.value == ''test3, test4''">click > > me</a> > > > > ...but I can''t get it to work. Any suggestions? > > > > Thanks, > > > > Steve > > http://www.smarkets.net > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060401/964175c9/attachment.html
Nope, can''t see a problem with that. If it works for you it should work for anyone... nothing browser specific there. -N On 01/04/06, Steve Odom <steve.odom@gmail.com> wrote:> Thanks to both of you for the help. Your comments helped steer me in the > right direction. > > I''m using the behaviour.js library so has allowed me to simplify it > somewhat. Here is my js: > > ''.tag_link'' : function(el){ > el.onclick = function(){ > var str = document.tag_form.discover.value + ", > " + el.rel > document.tag_form.discover.value = str; > } > }, > > And my form: > > <form name="tag_form"> > > <input type="text" name="all" id="discover" size="16" value="test1, test2"/> > <a href="#" rel="mytag1" class="tag_link">click me</a><br /> > <a href="#" rel="mytag2" class="tag_link">click me</a><br /> > <a href="#" rel="mytag3" class="tag_link">click me</a><br /> > </form> > > It validates (except for not having an action in the form tag, which I''ll > add in a bit. Does anyone see any problems with this? Seems to work fine. > > > Steve > http://www.smarkets.net > > > On 3/31/06, njmacinnes@gmail.com <njmacinnes@gmail.com > wrote: > > Well, first of all, the button should be between the <form> ... > > </form> tags (it should work even if not, but lets just be strictly > > correct). > > Your form needs a name, for example <form name="form1">. Then its'' > > onClick="document.form1.discover.value = test3, test4" Notice only one > > equals, not two? That should sort it out. Hope that''s helped. > > -N > > > > On 31/03/06, Steve Odom <steve.odom@gmail.com> wrote: > > > Hi list, > > > > > > I have a list of tags. I want to be able to click on a tag and have that > tag > > > name populate an input field. I think delicious used to allow you to > click > > > on existing links to tag your bookmark similar to this (moving instead > to > > > auto_complete). > > > > > > My guess is the code looks something like this.... > > > <form> > > > <input type="text" name="all" id="discover" size="16" value="test1, > test2"/> > > > </form> > > > > > > <a href onClick=" document.form.discover.value == ''test3, test4''">click > > > me</a> > > > > > > ...but I can''t get it to work. Any suggestions? > > > > > > Thanks, > > > > > > Steve > > > http://www.smarkets.net > > > > > > _______________________________________________ > > > Rails mailing list > > > Rails@lists.rubyonrails.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >