473,394 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

writing information from a button into a text box

hi im literally a complete amateur at the but i was wondering how to write the information from a button e.g. A into a text box. I know it involves an onclick command but i just can figure it out. any help would be greatly appreciated below is what i already have:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Page Title</title>
  4. </head>
  5. <body>
  6. <h1>Table</h1>
  7. <form>
  8.     <table border="1">
  9.  <tr>
  10.  
  11.       <td><input type='button' value='A' /></td>
  12.      <td><input type='button' value='B' /></td>
  13. </tr>
  14.  </table>
  15.  
  16.  <input type="text" name="searchbox" size=15>
  17.  <div style="position:absolute; left:150px; top 150px;"></div>
  18.  
  19. </form>
  20. <hr />
  21. </body>
  22. </html>
Dec 7 '09 #1
3 1978
Dormilich
8,658 Expert Mod 8TB
the procedure is quite simple:
write a function, where the value of the button is written to the target element’s value.
pass function to event handler

Expand|Select|Wrap|Line Numbers
  1. // put an id to the elements, so that you can access them easily
  2.  
  3. // write value to target
  4. // "this" will later refer to the button
  5. function passValue()
  6. {
  7.     document.getElementById("target_input").value = this.value;
  8. }
  9.  
  10. // register events (Button A, Button B)
  11. document.getElementById("btnA").addEventListener("click", passValue, false);
  12. document.getElementById("btnB").addEventListener("click", passValue, false);
  13. // IE’s poor event handling requires a workaround, so google for the addEvent() crossbrowser solution
Dec 7 '09 #2
DMsy2
15
A simpler way could be
Expand|Select|Wrap|Line Numbers
  1. <input type='button' value='A'  onclick="this.form.searchbox.value=this.value;" />
Dec 8 '09 #3
Dormilich
8,658 Expert Mod 8TB
"simple" is a matter of preference. suppose you want to change the target element…
Dec 8 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Aaron | last post by:
Hello, I have a small application that I need to save data from 7 text boxes in to a csv file. This will entail btnNext_Click function that will create a new csv file and enter the 7 data fields...
3
by: Jennifer | last post by:
On an ASP page I've got some code that is supposed to "export" data in a grid to an Excel file. What I'm doing is writing all the data to a text file, separating the fields by commas. Then I'll...
16
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
4
by: Marc | last post by:
Hi, I have a button on a form that, when pressed, adds additional user defined buttons to the form. I need to be able to save the user preferences and thought the best way would be to write the...
0
by: hshah | last post by:
Hello All, I have created a .aspx page with 7 text boxes and a save button. On click event following code is fired. It save the property information to sql server and also generate a unique Id...
1
by: programming | last post by:
Hi all, i am having trouble trying to write a script to a txt file. I am attempting to seperate each posted item with the deliminater '|', but for some reason i am getting the following...
5
by: mturner64 | last post by:
I am developing an application using asp.net where a user can enter first name, last name, donation amount, date, et cetera. After the user enters the information and clicks submit, the information...
6
by: L. Ximenes | last post by:
Greetings, I've recently been struggling with the idea of writing an XML document based on user-submitted content using javascript. Using various instances of document.write on a newly opened...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.