JavaScript Increment Issue

Tuesday, November 12, 2013

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

--
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.

Copyright © 2010 Web Design | Free Blogger Templates by Splashy Templates | Layout by Atomic Website Templates

Vida de bombeiro Recipes Informatica Humor Jokes Mensagens Curiosity Saude Video Games Animals Diario das Mensagens Eletronica Rei Jesus News Noticias da TV Artesanato Esportes Noticias Atuais Games Pets Career Religion Recreation Business Education Autos Academics Style Television Programming Motosport Humor News The Games Home Downs World News Internet Design Entertaimment Celebrities 1001 Games Doctor Pets Net Downs World Enter Jesus Mensagensr Android Rub Letras Dialogue cosmetics Genexus lasofia thebushrajr wingshock tripedes gorduravegetal dainfamia dejavu-transpersonal jsbenfica republicadasbadanas ruiherbon iranianforaryans eaystcheyl fotosdanadir Só Humor Curiosity Gifs Medical Female American Health Madeira Designer PPS Divertidas Estate Travel Estate Writing Computer Matilde Ocultos Matilde futebolcomnoticias girassol lettheworldturn topdigitalnet Bem amado enjohnny produceideas foodasticos cronicasdoimaginario downloadsdegraca compactandoletras newcuriosidades blogdoarmario arrozinhoii