javascript - What's wrong with my Loop -


i'm new in javascript , there thing wrong in codes cannot find it! driving me crazy.

ok, want do, user chooses how many poets worked write poem. if number 1 or no number entered outcome same, is, user enters last name , initial of poet , function puts in desired order, when more 1 poet (in example 2) want ask next poet's last name , initial, used array, reason result based on first poet's details only, this: lname(0), iname(0) & ,
, doesn't ask second poet's lname , initial! please let me know doing wrong!

 var initial, lastname, authors;     var num=1;     var iname = [],lname = [];     var index = 0;      num=bookform.txtnumber.value;     num=number(num);     if (num > 1) {           if (num == 2) {             while (index <= 1){                 iname[index] = bookform.txtinitial.value;                 lname[index] = bookform.txtlastname.value;                 bookform.txtinitial.value="";                 bookform.txtlastname.value="";                 bookform.txtinitial.focus();                 index = index + 1;             }             authors = lname[0]+", "+iname[0]+" & "+lname[1]+", "+iname[1]+" "         }     }     else {     initial = bookform.txtinitial.value+" "     lastname = bookform.txtlastname.value+", ";     authors = lastname+initial;     } 

it looks, reinitialize value of field

bookform.txtinitial.value=""; bookform.txtlastname.value="";

when pass second time in loop, value empty.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -