Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Funny little Javascript Array problem

Status
Not open for further replies.

4waystop

Programmer
Aug 30, 2004
19
GB
I'm having a little problem with getting data back out of Javascript arrays. I guess the two different methods or storing slightly different data somehow. My array is initialized as such:
Code:
var payment = new Object();
payment.cc = new Object();
If there is data present when the database is loaded then the arrays are populated like this:
Code:
<% Response.Write("payment['cc']['cvs']="+rsCredit('CVS')+";"); %>
Else, if the data is entered after the form has been loaded by the user then the arrays are populated like this:
Code:
payment['cc']['cvs'] = document.getElementById('cvs').value;
In both cases the data enters the arrays correctly, the problem comes when I want to show it in a new textbox. If it was put in by the first method it displays correctly, but if it was put in by the second method I simply get a blank textbox. This is the code:
Code:
document.getElementById("pay_r5").innerHTML = "<input type='text' name='cvs' id='cvs' size='3' tabindex='8' value='"+payment['cc']['cvs']+"'>";
Any ideas where to look or suggestions on this one?!

Oh - in addition if the data is initially loaded from the database, but later edited by the user (hence stored with the second method) it will show up correctly in subsequent text boxes.

Many Thanks!
 
So the second method populates the property with the value of an existing textbox called "cvs". Then you put that property as the value of a new textbox that is also called "cvs"? Why are there two textboxes with the same name? I feel there's something missing here. Are you doing a form submit in between the two steps or something? Can you post more of the code you're using?

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
I've got to ask... If you are using "payment" as an array, then why not define it as a new array (var payment = new Array(); or var payment = [];) rather than using an object which wont support any of the methods that the array object does?

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top