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.
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.
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.
Code:
html
<html>
<head>
<title></title> <script language = "javascript" type="text/javascript" src="rent.js"> </script> </head>
<body>
<script language = "javascript" type="text/javascript">
var rent =new Array();
rent[0] = new Rent("tenantA", 1000, "HouseA");
rent[1] = new Rent("tenantb", 2500, "HouseB");
rent[2] = new Rent ("tenantc", 6000, "Housec");
</script>
<form>
Tenant name : <input type="text" name="tenantTxt" /> <br/>
Rent Due : <input type="text" name="priceTxt" /> <br/>
Property : <input type = "text" name="propertyTxt" />
<br/>
<input type="button" name = "Tenant1" value="Tenant 1" onClick =" (document.forms[0][1].value=(rent[0].price)); "/>
<input type="button" name = "Tenant2" value="Tenant 2" onClick =" (document.forms[0][1].value=(rent[1].price)); "/>
</form>
</body>
</html>
Code:
rent.js
function Rent(tenantName, price, property){
this.tenantName = tenantName;
this.price = price;
this.property = property;
this. toTextboxData = toTextboxData;
}
function toTextboxData(){
tenantInfo = this.tenantName;
propertyPrice = this.price ;
propertyName = this.property;
return tenantInfo + propertyPrice + propertyName
}
Thank you.
Comment