html - Save multiple selection of dropdown list to variables using Javascript -


i have there dropdown lists values, , 1 textarea write valuse in. when press button writes values of 3 selected dropdown lists, every time when press button (it 3 times). pice of code writes values of dropodown lists, this: button pressed first time: "conntent of dropdown lists" undefinedundefined button pressed second time: undefined"conntent of dropdown lists"undefined button pressed third time: undefinedundefined"conntent of dropdown lists"

but want values of dropdown list not "undefined"

what can think of?

var = 0; function inc(){ i++;  if (i == 1){ var ukupnaporudzbina1 = vrstename + ' -> ' + podvrstename + ' -> ' + velicinename + i; }else if (i == 2){ var ukupnaporudzbina2 = vrstename + ' -> ' + podvrstename + ' -> ' + velicinename + i; }else if (i == 3){ var ukupnaporudzbina3 = vrstename + ' -> ' + podvrstename + ' -> ' + velicinename + i; } var porudzba = ukupnaporudzbina1 + ukupnaporudzbina2 + ukupnaporudzbina3;     document.frmmain.porudzbaholder.value = porudzba ; } 

vrstename is:

vrstename = document.frmmain.vrste.options[document.frmmain.vrste.selectedindex].text 

podvrstename , velicinaname same sort

and html part is:

<textarea name="porudzbaholder" rows="4"> </textarea> <input type="button" value="dodaj porudzbinu" onclick="inc();"/> 

thx in advance...

this because declaring 1 of 3 variables each time, referencing 3 later. try declaring variables first , initializing them "":

var ukupnaporudzbina1 = ""; var ukupnaporudzbina2 = ""; var ukupnaporudzbina3 = ""; 

then run rest of code written, leaving var out before each assignment ukupnaporudzbina.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -