473,395 Members | 1,473 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,395 software developers and data experts.

If button clicked, value should be reflected in text box

Java script:
If i click a button, the value should be reflected in a text box.
For
Ex:
<input name="textfield" type="text" />
<input type="button" name="button1" onclick="type('A')" />


Can any help me in java script for the above code for onclick event

THANKS in advance
Jul 1 '08 #1
7 1530
ajos
283 100+
You would have to try it here JavaScript forum .

This is a java forum....see the difference? Java/JavaScript
Jul 1 '08 #2
acoder
16,027 Expert Mod 8TB
Can you show the code for your type function, so we can suggest changes.

PS. changed the thread title to give it a better description.
Jul 1 '08 #3
Thanks for your response.

Here is the code.. Please help me.

Expand|Select|Wrap|Line Numbers
  1. <input name="textfield" type="text" />
  2. <img src="images/q.gif" width="46" height="48" onclick="type(q)" />
  3. <img src="images/r.gif" width="46" height="48" onclick="type(r)" />
  4.  
  5. <SCRIPT type="text/javascript" >
  6. function type(xx){
  7.     var  object =document.getElementById("textfield");
  8.     var append = object.value;
  9.     object.value=append+xx;
  10. }
  11.  
  12. </script>
  13.  
Im not getting any value in the text box.
Pls suggest
Jul 1 '08 #4
acoder
16,027 Expert Mod 8TB
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future. Thanks!
Jul 1 '08 #5
acoder
16,027 Expert Mod 8TB
Im not getting any value in the text box.
That's because q and r are not strings and are not defined anywhere. Pass them as strings:
Expand|Select|Wrap|Line Numbers
  1. onclick="type('q')"
Secondly, the text field does not have an id, so using document.getElementById("textfield") won't work (in most browsers, at least). Give your text input field an id.
Jul 1 '08 #6
Many Thanks.. It's working.. :)
Jul 1 '08 #7
acoder
16,027 Expert Mod 8TB
You're welcome. Glad to hear it.
Jul 1 '08 #8

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

Similar topics

6
by: Rod Snyder | last post by:
I'm trying to set up a page with an asp.net link button that would send a user to a certain page and on page load execute a specific stored procedure tied to the button on the previous page. The...
0
by: Oz | last post by:
Hi Using VS.NET 2003, Windows XP SP1, We have a page which has been developed using ASP.NET. On it, is a button which when clicked is supposed to add some data to a table. When the button is...
1
by: rn5a | last post by:
I want to create a custom control that encapsulates a Button & a TextBox. When the Button is clicked, the user is asked a question using JavaScript confirm (which shows 2 buttons - 'OK' &...
3
by: AlecL | last post by:
Hi All, I am trying to capture the value of a textbox as a result of a button click event in a repeater, but it can't find the textbox. Here is what I am trying to do in the code for the click...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.