I have a problem regarding this two values from my textboxes (text, text2), seems like text2 only show its value, is there any way I can get rid of these things. Any help would be so much appreciated.
parameters = ('text=' + document.getElementById('text').value) && ('text2=' + document.getElementById('text2').value;
xmlhttp.open('POST', 'try.php', true);
xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlhttp.send(parameters);
This line is wrong.
&&does not mean “concatenate”: it means “logical and”. Basically, it means “returnfalseif either side of the operator is falsy, otherwise, return the right-hand-side”. So this will always return'text2=' + document.getElementById('text2').value, because this is the right-hand-side of the&&operator.You need to concatenate them, for which the operator, as you use quite correctly otherwise, is
+.Note that you should probably also use
encodeURIComponentto make sure you’re making valid HTTP requests: