Hello:
I have a question to anyone that may know the answer. I'm creating unique id dynamically so I added
a counter. It works fine the first time but second item created ends up with the same id which leads
me to know that my counter is not being incremented properly.
function registerCreditCard(){ //main function
some more code it just to much to include
button.onclick = function() { // Note this is a function This is the Calling function for updatebutton
alert("creating form and dialog");
/**************Create Update Form******************/
var element2 = document.getElementById("creditCards");
var parent2= element2.parentNode;
var itemCount = 0;
var newElement = document.createElement('div');
newElement.setAttribute("id", 'updateCC' + ++itemCount); //count is now 1
newElement.setAttribute("style","display:none;");
more code and button is clicked and it goes back to calling function
}
}
This is one huge function inside other functions but the bottom line is when the function returns it dosen't keep the itemCount,
it initializes back to 0;
I can't use any looping because it won't hit the other function until looping finishes then of course it would break.
My question is, is there any other way to keep the count from initializing back to zero without using a for loop etc looping
once the function returns? I tryed return itemCount with no luck :( I let this a long for while and started working on another project
but I knew I had to come back to it. This is the last part of the section that has me at a stand still. I worked on it for hours today and can't
keep the count on coding I have tried.
Thanking You in Advance,
PH
-- I have a question to anyone that may know the answer. I'm creating unique id dynamically so I added
a counter. It works fine the first time but second item created ends up with the same id which leads
me to know that my counter is not being incremented properly.
function registerCreditCard(){ //main function
some more code it just to much to include
button.onclick = function() { // Note this is a function This is the Calling function for updatebutton
alert("creating form and dialog");
/**************Create Update Form******************/
var element2 = document.getElementById("creditCards");
var parent2= element2.parentNode;
var itemCount = 0;
var newElement = document.createElement('div');
newElement.setAttribute("id", 'updateCC' + ++itemCount); //count is now 1
newElement.setAttribute("style","display:none;");
more code and button is clicked and it goes back to calling function
}
}
This is one huge function inside other functions but the bottom line is when the function returns it dosen't keep the itemCount,
it initializes back to 0;
I can't use any looping because it won't hit the other function until looping finishes then of course it would break.
My question is, is there any other way to keep the count from initializing back to zero without using a for loop etc looping
once the function returns? I tryed return itemCount with no luck :( I let this a long for while and started working on another project
but I knew I had to come back to it. This is the last part of the section that has me at a stand still. I worked on it for hours today and can't
keep the count on coding I have tried.
Thanking You in Advance,
PH
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.