Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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.

Reply With Quote
  #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)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:07 AM.


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