Javascript help


#1

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


#2

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

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 :wink:


#3

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

#4

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


#5

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