javascript - Add text to input field using text hyperlink -


This may be a dummy question but I can not find a solution for this.

We have a piece of code:

  & lt; Script type = "text / javascript" & gt; $ (Function () {$ ('. Tag_selected'). (Function () {var value = $ (this) .text (); var input = $ ('# text_tag_input'); input.val ( Input Val () + value + ','); Returned;});}); & Lt; / Script & gt;  

and HTML:

  & lt; Input id = "text_tag_input" type = "text" name = "tag" /> & Lt; Div class = "tags_select" & gt; & Lt; A href = "#" & gt; Text1 & lt; / A & gt; & Lt; A href = "#" & gt; Text2 & lt; / A & gt; & Lt; A href = "#" & gt; Text3 & lt; / A & gt; & Lt; / Div & gt;  

The problem is following - when I click on link text 1, and then text2 etc. Everything appears in the input, what I want to achieve is to display only one variable (in this case, in the latest, final form).

This should work for you

< Pre> & lt; Script type = "text / javascript" & gt; Val (""); Var value = $ (this) .text (); Var input = ($. $ ('# Text_tag_input'). Val (value); return false;});}); & Lt; / Script & gt; & Lt; Input id = "text_tag_input" type = "text" name = "tag" /> & Lt; Div class = "tags_select" & gt; & Lt; A href = "#" & gt; Text1 & lt; / A & gt; & Lt; A href = "#" & gt; Text2 & lt; / A & gt; & Lt; A href = "#" & gt; Text3 & lt; / A & gt; & Lt; / Div & gt;

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -