473,395 Members | 2,010 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.

value to textbox question.

28
Hi,

I have an array with some data(tenant, price, property) that I would like to place in a few text boxes of a form when someone clicks a button.

I am only able to put one element of an array to the text box at a time like price or tenant or property but I would like to put all three data into their textbox when a button is clicked.

###ex. what I have###
tenant name:
rent due: price
property:

onclick show tenant(#)
##############################

###ex. what I would like###
tenant name: tenantname
rent due: price
property: HouseA

onclick show tenant(#)
###########################

So far if I put an alert box the code works I use the function toTextboxData() but its passing it to the textboxes that I have problems with.

I would appreciate any help that any one could offer.

Thank you in advance,
-sean.

Expand|Select|Wrap|Line Numbers
  1. html
  2. <html>
  3.     <head>
  4.         <title></title> <script language = "javascript" type="text/javascript" src="rent.js">  </script> </head>
  5.     <body>
  6.         <script language = "javascript" type="text/javascript">
  7.             var rent =new Array();
  8.            rent[0] = new Rent("tenantA", 1000, "HouseA");
  9.             rent[1] = new Rent("tenantb", 2500, "HouseB");
  10.             rent[2] = new Rent ("tenantc", 6000, "Housec");
  11.  
  12.  
  13.         </script>
  14.         <form>
  15.            Tenant name : <input type="text" name="tenantTxt" />  <br/>
  16.            Rent Due : <input type="text" name="priceTxt" />  <br/>
  17.             Property : <input type = "text" name="propertyTxt" />
  18.             <br/>        
  19.  
  20.         <input type="button" name = "Tenant1" value="Tenant 1" onClick =" (document.forms[0][1].value=(rent[0].price)); "/>        
  21.             <input type="button" name = "Tenant2" value="Tenant 2" onClick =" (document.forms[0][1].value=(rent[1].price)); "/>        
  22.  
  23.  
  24.  
  25.         </form>
  26.     </body>
  27. </html>
  28.  
Expand|Select|Wrap|Line Numbers
  1. rent.js
  2.  function Rent(tenantName, price, property){
  3.      this.tenantName = tenantName;
  4.     this.price = price;
  5.     this.property = property;
  6.    this. toTextboxData =  toTextboxData;
  7.  }
  8.  function toTextboxData(){
  9.      tenantInfo = this.tenantName;
  10.      propertyPrice = this.price ;
  11.      propertyName =  this.property;
  12.           return tenantInfo + propertyPrice + propertyName
  13.  
  14.     }
  15.  
  16.  
Is there a way to use toTextboxData() function to print to the text box or is there a better way of passing value to a form , the way I'm using the onclick doesn't seem to work. Any help would be greatly appreciated.

Thank you.
Feb 28 '11 #1

✓ answered by dgreenhouse

Using your code this should work.
{Note: I included the code from rent.js (object definition) in the head.}

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     <title></title>  
  4.  
  5.      <script language = "javascript" type="text/javascript">
  6.        rent = new Array();
  7.        rent[0] = new Rent("tenantA", 1000, "HouseA");
  8.        rent[1] = new Rent("tenantB", 2500, "HouseB");
  9.        rent[2] = new Rent ("tenantC", 6000, "HouseC");
  10.  
  11.        function getTenantInfo(index) {
  12.          document.forms[0][0].value = rent[index].tenantName;
  13.          document.forms[0][1].value = rent[index].price;
  14.          document.forms[0][2].value = rent[index].property;
  15.          document.forms[0][3].value = rent[index].toTextboxData();
  16.        }
  17.  
  18.        function Rent(tenantName, price, property){
  19.          this.tenantName = tenantName;
  20.          this.price = price;
  21.          this.property = property;
  22.          this.toTextboxData =  toTextboxData;
  23.        }
  24.  
  25.        function toTextboxData(){
  26.          tenantInfo = this.tenantName;
  27.          propertyPrice = this.price ;
  28.          propertyName =  this.property;
  29.          return tenantInfo + ', ' + propertyPrice + ', ' + propertyName;
  30.        }       
  31.   </script>
  32. </head>
  33.   <body>
  34.     <form>
  35.       Tenant name : <input type="text" name="tenantTxt" />  <br/>
  36.       Rent Due : <input type="text" name="priceTxt" />  <br/>
  37.       Property : <input type="text" name="propertyTxt" /> <br/>
  38.       TextBox : <input type="text" name="toTextBox" />
  39.       <br/>        
  40.       <input type="button" name = "Tenant1" value="Tenant 1" onClick ="getTenantInfo(0)"/>        
  41.       <input type="button" name = "Tenant2" value="Tenant 2" onClick ="getTenantInfo(1)"/>
  42.       <input type="button" name = "Tenant3" value="Tenant 3" onClick ="getTenantInfo(2)"/>        
  43.      </form>
  44.   </body>
  45. </html>
  46.  

2 1329
dgreenhouse
250 Expert 100+
Using your code this should work.
{Note: I included the code from rent.js (object definition) in the head.}

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     <title></title>  
  4.  
  5.      <script language = "javascript" type="text/javascript">
  6.        rent = new Array();
  7.        rent[0] = new Rent("tenantA", 1000, "HouseA");
  8.        rent[1] = new Rent("tenantB", 2500, "HouseB");
  9.        rent[2] = new Rent ("tenantC", 6000, "HouseC");
  10.  
  11.        function getTenantInfo(index) {
  12.          document.forms[0][0].value = rent[index].tenantName;
  13.          document.forms[0][1].value = rent[index].price;
  14.          document.forms[0][2].value = rent[index].property;
  15.          document.forms[0][3].value = rent[index].toTextboxData();
  16.        }
  17.  
  18.        function Rent(tenantName, price, property){
  19.          this.tenantName = tenantName;
  20.          this.price = price;
  21.          this.property = property;
  22.          this.toTextboxData =  toTextboxData;
  23.        }
  24.  
  25.        function toTextboxData(){
  26.          tenantInfo = this.tenantName;
  27.          propertyPrice = this.price ;
  28.          propertyName =  this.property;
  29.          return tenantInfo + ', ' + propertyPrice + ', ' + propertyName;
  30.        }       
  31.   </script>
  32. </head>
  33.   <body>
  34.     <form>
  35.       Tenant name : <input type="text" name="tenantTxt" />  <br/>
  36.       Rent Due : <input type="text" name="priceTxt" />  <br/>
  37.       Property : <input type="text" name="propertyTxt" /> <br/>
  38.       TextBox : <input type="text" name="toTextBox" />
  39.       <br/>        
  40.       <input type="button" name = "Tenant1" value="Tenant 1" onClick ="getTenantInfo(0)"/>        
  41.       <input type="button" name = "Tenant2" value="Tenant 2" onClick ="getTenantInfo(1)"/>
  42.       <input type="button" name = "Tenant3" value="Tenant 3" onClick ="getTenantInfo(2)"/>        
  43.      </form>
  44.   </body>
  45. </html>
  46.  
Mar 1 '11 #2
seanh
28
Hi dgreenhouse,
Oh my goodness! Thank you so very much, Your a Genius!
Thank you so much for your understanding and prompt answer.
-sean
Mar 1 '11 #3

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

Similar topics

11
by: Sweety | last post by:
hello to all members, i have strange question in C. main() { printf("%d",main) ; } here o/p is same for all m/c in TC++ version 3.0 i.e 657. I think this is not garbage.
2
by: Maziar Aflatoun | last post by:
Hi, I'm dynamically creating text boxes (<asp:textbox>) based on the column names in database. Now, I might have a textbox with id="Your height", how would I read the value of that in my...
2
by: Paul | last post by:
I have a user that when tabs to a textbox notices that the curser lines up with the end of the current text entry if the textbox is in the multiline mode. If the textbox is in the single line mode...
3
by: VB Programmer | last post by:
In my ASPX page how do I get the .text value of a textbox that is in the ItemTemplate of a datalist (using HTML)? The textbox contains the quantity for a shopping cart item. The textbox is...
2
by: hamil | last post by:
I have a form with a text box, a thread start button, and a seperate thread. This is a TCP listener (server) example I took out of a book. See the code below. In the loop below, look at the two...
1
by: melanieab | last post by:
Hi, If there's a textbox and the text entered is longer than what's visible (the textbox length), how do you make it so that the beginning chunk of text is visible (instead of the last part of...
2
by: Eric | last post by:
I have a textbox on a form that is populated from the database when the form loads. When I check textbox.Text when the user clicks my submit button, the value is always what it was when the form...
10
by: Y2K | last post by:
Any suggestions to compare two values, and if either value changes, then both values now become the changed values. Right now I'm doing it with a textbox and onchange event, but would like to get...
10
by: garyusenet | last post by:
I have a multiline textbox. The size of the text box should be 75 characters wide, and 5 lines in height like this: - <---75 characters--> <---75 characters--> <---75 characters--> <---75...
3
by: Jeff Williams | last post by:
Is there a way I can place a Mask on a TextBox input so that say only numbers from 0 to 9 can be entered. Regards Jeff
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.