473,624 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

writing information from a button into a text box

1 New Member
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 1987
Dormilich
8,658 Recognized Expert Moderator Expert
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 New Member
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 Recognized Expert Moderator Expert
"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
52138
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 in the csv file; as well, each click on next will return carriage to a new line. Client does not what his data in an Access database(he hates Access with a passion)--he feels more comfortable with Excel. This data will be no greater than 1000...
3
7015
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 redirect the user to a new page with the file that was just created. Code: Dim objFSO, objTextFile Dim sRead, sReadLine, sReadAll Const ForReading = 1, ForWriting = 2, ForAppending = 8
16
2197
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
4
1007
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 information to a text file. Can anyone supply the code on how to write the newly created buttons name to a text file. As more than 1 new button may be created I want to store the information for each new button on a new line then read the
0
1351
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 for that porperty and fatch that id and show it on that screen. I have created a .cs file for TrustConnectionString as below. Can someone please help me or guide me, is this a good practice to write code? If not can you please help me how to...
1
3127
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 information written: peri|jones||||Submit Whereas the desired input should be as follows WITHOUT the submit button been printed and on a NEW LINE:
5
3172
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 is written/stored into an Access 2007 database, which works well. I am now wanting to allow a user to upload an image of themselves along with their text information and have that image stored in a field of the Access 2007 database. I have...
6
11721
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 window I succeeded in the task of outputting a perfectly valid XML document, although I have been experiencing a few problems. If I look at the source code of the new window, what I have is a perfect XML document, such that if I copy the source...
0
8246
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8685
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8631
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8490
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4184
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1489
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.