Im trying to retrieve a txt doc from server with ajax request. The name of the txt doc depends on a text input on html doc. Basically I want to append .txt to the end of the input field following an onclick event
// JavaScript Document
function getData(){
var xmlhttp;
var user=document.getElementById("nameDetails").value;
var userText = user + ".txt"; //**not the solution
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("userSubmit").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","userText",true);
xmlhttp.send();
}
If you want to append
.txtto the input field itself, you could try this:or the short form: