473,495 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using onClick to paste code

28 New Member
Hi,

I am working on having a button click and then it will paste code into a selected box.

I am having a little bit of an issue though.

First my code:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script type="text/javascript">
  5. function check(browser)
  6.   {
  7.   document.getElementById("answer").value=browser;
  8.   }
  9. </script>
  10.  
  11. </head>
  12. <body>
  13.  
  14. <form>
  15. <input type="button" onclick="check(this.id)" id='<a href="http://bikramhotyoga.ca/index.php/instructors/michael-ashton/">Michael</a>' value="Michael"<br />
  16. <input type="button" onclick="check(this.id)" id='<a href="http://bikramhotyoga.ca/index.php/instructors/dan-durand/">Dan</a>' value="Dan"<br />
  17. <input type="button" onclick="check(this.id)" id='<a href="http://bikramhotyoga.ca/index.php/instructors/barb-towell/">Barb</a>' value="Barb"<br />
  18. <input type="button" onclick="check(this.id)" id='<a href="http://bikramhotyoga.ca/index.php/instructors/gulie-ajania/">Gulie</a>' value="Gulie"<br />
  19. <br /><br />
  20. The teacher is: <input type="text" id="answer" size="20">
  21. The teacher is: <input type="text" id="2" size="20">
  22. </form>
  23.  
  24. </body>
  25. </html>
  26.  
  27.  
Two things:

1) It will only paste into the box that has an id of 'answer' instead of a selected box.


Can anyone help me with this?

Thanks!!

Cheers,

Michael
Apr 20 '08 #1
5 1797
acoder
16,027 Recognized Expert Moderator MVP
What do you mean by selected box? Do you mean the one which has focus?

Note that you haven't closed your input buttons properly.
Apr 20 '08 #2
mrking
28 New Member
Oops, thanks.

I have multiple text boxes on one page and would like to place my cursor in a box, click the button and the text value will paste into it. Click on another text box, click, paste. Etc.

Right now it will only paste into a text box with an id of 'answer'

Is there a way to have it paste in whatever box I select?
Apr 21 '08 #3
pronerd
392 Recognized Expert Contributor
Is there a way to have it paste in whatever box I select?
It is only selecting the one with the value of 'answer', because you hard coded the string 'answer' as the ID value to pull. So pass the ID of the field you want to use, and then pull that element.

Expand|Select|Wrap|Line Numbers
  1.       <script type="text/javascript">
  2.  
  3.       function check(browser, fieldId)  {
  4.         document.getElementById(fieldId).value=browser;
  5.         }
  6.       </script>
  7.  
Apr 21 '08 #4
mrking
28 New Member
It is only selecting the one with the value of 'answer', because you hard coded the string 'answer' as the ID value to pull. So pass the ID of the field you want to use, and then pull that element.

Expand|Select|Wrap|Line Numbers
  1.       <script type="text/javascript">
  2.  
  3.       function check(browser, fieldId)  {
  4.         document.getElementById(fieldId).value=browser;
  5.         }
  6.       </script>
  7.  
I tried this code but with not luck. I placed my cursor in the text box, click one of the buttons and nothing happens.
Apr 23 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
You will need to keep a reference to currently focused element using the onfocus event handler of each text box.
Apr 23 '08 #6

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

Similar topics

2
478
by: Cathy | last post by:
Has anyone ever made a webform button run an onClick event that is a Javascript in the HTML code and then after running the script make it go into the code-behind? An HTML button will run the...
2
2715
by: jdub | last post by:
I bringing up a list of movies in a separate window where each one has an "onclick" function which is suppose to call a procedure and pass in the variables and display the details of the selected...
4
2826
by: @sh | last post by:
Can anyone help out here please, we have a button that when pressed will alert the user, should they cancel no action is taken, however should they confirm, the script will disable the button and...
10
67727
by: Eric-Sebastien Lachance | last post by:
Hey there, I decided to just create a 100% height and width div that filled the space over a background header image, and add an onclick event to redirect to the my index... Doesn't seem to work...
5
2129
by: ElanKathir | last post by:
Hi ! I wrote one code for Send the E-mail, But that code have some problem , So please help me Here i paste my code and Error: Error: Server Error in '/Elan_Sample' Application. ...
13
1946
by: Benjamin Smith | last post by:
I am controlling the display status of a table row using the following code. <TR id="CCRow" style="DISPLAY:none"> Instead of hard coding "none" above, I would like to change that value using a...
6
1794
by: Murray Hopkins | last post by:
Hi. THE QUESTION: How do I get a reference to my Object when processing an event handler bound to an html element ? CONTEXT: Sorry if it is a bit long. I am developing a JS calendar tool....
1
2856
by: bsprogs | last post by:
I am currnetly programming a file hosting website in PHP and I am slowly integrating AJAX into the website. Here is my problem: The user uploads the file. The server processes the file and...
11
4430
by: gan | last post by:
hi dear all please help me im using the calander control from a form just i paste here the problem, the problem is when i click the calander button the calander is opening at the same time...
0
7120
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
6991
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
7196
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...
0
5456
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,...
1
4897
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...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
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...

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.