I have this js….
$("#form").submit(function(){
var answerlist = "first";
var answerlist = answerlist + "," + $("#get_answer").attr("value");
alert(answerlist);
});
i’m trying to add the value of the input field with the id #get_answer to the answelist variable….
i expect that the answerlist is now = first move // where the value of input field is move and yes the result is a success…
and now for the second time around i’m trying to add another value to the answerlist variable….
the value is on
i expect that the outcome will be first move on
but when i check using the alert() it returns first on
can someone help me plsss??
what i want is to increment the value(string) to the variable answerlist
like
answerlist = "first";
answerlist = "first move";
answerlist = "first move on";
You are initializing the value of the variable inside the function, so naturally, when it’s called once again the value will return to first
Initialize it outside the function.