# Javascript help

**URL:** <https://www.ruby-forum.com/t/javascript-help/56527>\
**Category:** Rails\
**Created:** [March 31, 2006, 10:09pm UTC](https://www.ruby-forum.com/t/javascript-help/56527 "2006-03-31T22:09:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![steveoco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@steveoco](https://www.ruby-forum.com/u/steveoco)\
**Post date:** [March 31, 2006, 10:09pm UTC](https://www.ruby-forum.com/t/javascript-help/56527/1 "2006-03-31T22:09:09Z")

</div>

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…

click  
me

…but I can’t get it to work. Any suggestions?

Thanks,

Steve  
[http://www.smarkets.net](http://www.smarkets.net)

---

<div class="post-metadata">

**Author:** ![steveoco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@steveoco](https://www.ruby-forum.com/u/steveoco)\
**Post date:** [March 31, 2006, 10:30pm UTC](https://www.ruby-forum.com/t/javascript-help/56527/2 "2006-03-31T22:30:05Z")

</div>

Steve O. 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…
> 
> click  
> me
> 
> …but I can’t get it to work. Any suggestions?
> 
> Thanks,
> 
> Steve  
> [http://www.smarkets.net](http://www.smarkets.net)

You 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

# In the body of the page
click me

This should work! Have fun 😉

---

<div class="post-metadata">

**Author:** ![steveoco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@steveoco](https://www.ruby-forum.com/u/steveoco)\
**Post date:** [March 31, 2006, 10:36pm UTC](https://www.ruby-forum.com/t/javascript-help/56527/3 "2006-03-31T22:36:48Z")

</div>

Well, first of all, the button should be between the …

 tags (it should work even if not, but lets just be strictly correct). Your form needs a name, for example . 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

---

<div class="post-metadata">

**Author:** ![steveoco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@steveoco](https://www.ruby-forum.com/u/steveoco)\
**Post date:** [April 1, 2006, 4:36am UTC](https://www.ruby-forum.com/t/javascript-help/56527/4 "2006-04-01T04:36:15Z")

</div>

Nope, can’t see a problem with that. If it works for you it should  
work for anyone… nothing browser specific there.  
-N

---

<div class="post-metadata">

**Author:** ![steveoco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/db5fbb/32.png) [@steveoco](https://www.ruby-forum.com/u/steveoco)\
**Post date:** [April 1, 2006, 2:43am UTC](https://www.ruby-forum.com/t/javascript-help/56527/5 "2006-04-01T02:43:48Z")

</div>

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:

click me  
click me  
click me  

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](http://www.smarkets.net)
