html link to change the value of a textbox

I'm trying to create text in html, that once clicked, the the value of a textbox residing near it, changes its value to be equal to that of the text clicked. Is there anyway I can do that?

In other words, I want the functionality of a button (the onClick event) for a link/text. For example: What's wrong with this?

<td> <input type="submit" name="submit" value=<%=text.toString()%> onClick="(<% TextBox1.Text=text.toString()%>)" style="background:none;border:0;color:#ff0000"> </td>

-------------Problems Reply------------

Assuming the input has an id attribute with value "foo":

onclick="document.getElementById('foo').value='bar';"

Frameworks like JQuery can make this slightly simpler:

$('#foo').attr('value', 'bar');

One could add this event to a span element, for example. It's best practice to use script to set these events and special styles to reflect how they act, so that without script their different (lack of) behavior still looks intuitive.

You can do it like that :

<span onclick="document.getElementById('myTextbox').value=this.innerHTML;">text</span>
<input type="text" value="" id="myTextbox">

With JQuery :

<span onclick="$('#myTextbox').val(this.innerHTML);">text</span>
<input type="text" value="" id="myTextbox">

Category:javascript Views:0 Time:2009-05-02

Related post

  • (Basic jquery) pass the text of a link to a textbox 2009-12-11

    this is a really basic jQuery question, but i'm not sure how to do this: <input type=text class=city /> <ul class="cityList"> <li><a href="#">Test 1</a></li> <li><a href="#">Test 2</a></li>

  • jQuery .click() function - linking between two .click() functions (on seperate pages) and bringing up the related content 2011-07-04

    Okay, so I've got two .click() functions on two pages, which both work fine, no problem there. I need to be able to link from within one of the .click() functions to the other. How should the links be written or is the .click() function not right for

  • Change links color using a textbox and save with cookies 2011-07-25

    I'm tryng to develop a google chrome extension to change links color (on a vbulletin forum: links are online user on the first page of the forum). I add a link to save the cookie and a textbox: but when i add a user link it's ok because the color of

  • .Net textbox is null when a "submit" link is clicked 2011-11-28

    Good day, I have a problem in a .NET page where I am using an asp:textbox in combination with an OnClick action on a link button. What happens is that after text has been entered into the textbox, if you directly click on the link button, more often

  • Inserting a text where cursor is using Javascript/jquery 2009-06-30

    I have a page with a lot of textboxes. When someone clicks a link, i want a word or two to be inserted where the cursor is, or appended to the textbox which has the focus. For example, if the cursor/focus is on a textbox saying 'apple' and he clicks

  • TextBox binding in WPF 2009-07-23

    I have a textbox in XAML file, On Changing the text in the textbox the prop setter is not getting called. I am able to get the value in ProjectOfficer textbox and not able to update it. I am using MVVM pattern Below is my code XAML TextBox Text="{Bin

  • Gridview with TextBox 2009-08-18

    i have an gridview control with a comment text, link button, and an invisible (text box and a button to post to database.) when i click on the link button i want to show the textbox. can any one help me how to do this. my gridview code: <asp:GridV

  • Reusing OpenFileDialog 2010-01-13

    I have 2 textboxes and 2 button [...] next to each textbox. Is it possible to use one OpenFileDialog and pass the FilePath to the respective textbox, based on which button is clicked? i.e...if I click buttton one and laod the dialog, when I click ope

  • VB 2008 or VB 2010 Dataset help 2010-01-28

    I have three forms similar to the one in the link. I want add a Total textbox to every form. The total will add the values that will be entered in the montant textbox. So the total will take the specific value of that texbox for all the entries that

  • ASP MVC Populate drop down list on jQuery add table row 2010-04-22

    I have a page with several drop down lists that all have the same contents. The page starts out with only three ddls, but more need to be added based on user input. There is also other information associated with the drop down lists that is all in a

  • Mobile location tracking on Google maps 2010-04-27

    I need to develop a feature for one of my website by which user can track any mobile number on Google maps just like the link below. Go o the following link and enter the 9810098109 number in textbox to find its location on map. http://wwwa.way2sms.c

  • Unexpected scrolling when typing in a textbox after anchor top (Android-friendly mobile webpage development) 2010-06-25

    [Note that I can only reproduce the issue on the Android mobile web browser (used via emulator).] Summary After clicking an anchor to go to the bottom of the page, and another anchor to get to the top of the page - and typing within a textbox at the

  • .val() doesn't trigger .change() in jquery 2010-07-05

    I am trying to trigger .change() on a text box when I change it's value simply with a button but it doesn't work. Check this link. If you type something in textbox then click somewhere else .change() triggers but if you click only button, it changes

  • asp.net mvc adding css to editorfor? 2010-08-05

    I'd like to change style of the 'editor for' textbox from MVC, specifically I want to make the textbox larger. I've tried adding css a few ways, to no avail. including : <td class="myCss"><%=Html.EditorFor(x => x.NickName)%></td>

  • twitter like reply button using jquery and php get function? 2010-09-09

    i wanted to implemant the reply button so it takes a value through get function and put that in the update textbox just like twitter!! is thier a toturial or article, or you could guide me the right way i can do this!! --------------Solutions--------

  • how to access .skin file from aspx page 2010-10-28

    i have a .skin file inside my app.themes folder. To access .css file from asp page we have to give link. but i couldn't find any thing on asp header to give link for .skin file. <asp:TextBox SkinID="txtBox" ID="TextBox1" runat="server"></asp

  • Is it possible to trigger jQuery datepicker element on both input click and button? 2010-12-28

    I have an input text containing a default date and I'm using jQuery's Datepicker plugin to select a date from a popin calendar. This calendar pops in when the user clicks on the small picture next to the input. This is working great but I'd like to t

  • AutoComplete functionality for WPF application 2011-01-11

    I have 20 controls on my WPF page which are binded to a static resource "InsertClass". Out of those 20, one is a buyer texbox, on which user can enter the name of buyer. Now, what i require is that when a user starts entering, he should get a suggest

  • instance class from swc inside a movieclip 2011-02-03

    i'm trying to use compiled assets and code from a swc. Inside a new fla I select the swc to be included when exporting. When create the instance in the timeline of the code works and I can see assets that are inside the swc and trace a propertie from

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.160 (s). 11 q(s)