I found this code on the internet, I'm using it to populate a textbox with autocomplete elements, the problem I have tho is that I also have a DropDownList that lets you choose between three languages, and I would like to change a parameter depending on the selected language. This is the code:
<script language="javascript" type="text/javascript">
$(function () {
$('#<%=txtCompanyName.ClientID%>').autocomplete({
source: function (request, response) {
$.ajax({
url: "Default.aspx/GetCompanyName",
data: "{ 'pre':'" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data.d, function (item) {
return { value: item }
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
}
});
});
I would like to change the "url: Default.aspx/GetCompanyName" parameter everytime I switch the language on the DropDownList. I tried a lot of things, but I think the closest was this:
...
if(document.getElementById('DropDownListName').value == "Company")
url: "Default.aspx/GetCompanyName",
} else {
url: "Default.aspx/IgnoreInput",
}
...
Thanks in advance for the help!
ClientIDMode="static"on it, realize that the ID will not be what you expect. To see this first-hand, Right Click the dropdown and do Inspect Element, and examine the ID. Because of this,getElementById('DropDownListName')may not find anything. Cite your other example, where you're using<%=txtCompanyName.ClientID%>to fetch the rendered ID. Also, is that last snippet contained within an event to capture the dropdown changing, or is it just in the middle of your code...?