Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 18th, 2005, 11:59 PM
Registered User
 
Join Date: Jan 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default javascript onclick question

hello,

i want to prefill a form text input field with text that is contained on an HTML page.

ie.

<a href="javascript:onclick(TEXT)">TEXT</a>

Which, when clicked, will turn the input field to:

<input type=text value="TEXT">


and if they click on this link:
<a href="javascript:onclick(TEXT2)">TEXT2</a>

it wil change the text field to TEXT2, etc.

Please let me know if you guys have any suggestions.

Thanks a lot! MUch appreciated.

  #2 (permalink)  
Old January 19th, 2005, 05:20 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I would do it like this:
Code:
function setInputText(TargetId, Text)
{
  var oTarget = document.getElementById(TargetId);
  oTarget.value = Text;
}

<input type="text" id="txtName">
<a href="/" onclick="setInputText('txtName', this.innerText);return false;">Joe</a>

--

Joe (Microsoft MVP - XML)


Similar Threads
Thread Thread Starter Forum Replies Last Post
onclick="javascript: return false" on vista gabrieldcr2 Javascript 2 June 4th, 2008 09:40 AM
Adding onclick stuff to an INPUT via javascript p.ross BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 1 November 29th, 2005 01:08 PM
Javascript printing question? macupryk General .NET 0 October 30th, 2004 11:28 PM
Javascript question in my ASP code savoym Classic ASP Basics 3 May 24th, 2004 06:05 PM
question about Javascript capabilities DWoods57 Javascript How-To 1 December 18th, 2003 07:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.