I am trying to populate a dropdownlist with the result of the execution of an .exe program. The .exe will return a concatenation of items, separated by special characters. This will in turn be captured by the corresponding view at views.py, and rendered to the .html. In this .html, there is javascript code that runs on window load, splits the rendered string using the special characters and (theorically) populates the dropdownlist.
Part of my code is as follows:
the c++ code (will be compiled into the .exe)
while(i<MAX_ITEMS)
std::cout << i << "$" << item[i] << "&";
views.py (inside of the view that the url is calling)
os.chdir(r'C:/directory')
proc = subprocess.Popen([r'C:/directory/Application.exe'], stdout=subprocess.PIPE)
y = proc.stdout.read()
proc.wait()
return render_to_response('home.html', {'list': y})
finally, the html file containing the javascript function
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript" charset="utf-8">
window.onload = function Func() {
var lists = document.getElementById('list');
var liststxt = new Array();
liststxt[1] = "{{ list }}";
var items = liststxt[1].split("&");
for (var count = lists.options.length-1; count >-1; count--){
lists.options[count] = null;
}
for (i=0; items.length; i++){
var values = items[i].split("$");
var option = new Option(values[1], values[2], false, false);
lists.options[lists.length] = option;
}
}
</script>
</head>
<body>
<form action="" method="get" accept-charset="utf-8">
<select name="list" id="list">
<option>--</option>
</select>
</form>
</body>
</html>
I think I have tried almost all intermediate possibilities, and they work perfect (hardcoding a string instate of reciveing it from the exe, rendering the result of the .exe directly at the html instate of processing it using javascript, etc.), but if I put everything together, it fails to populate the dropdownlist...
I am doing this code in order to have several dependant dropdownlists, and I am doing it following the proof of concept seen here. I am not using Ajax (or Dajax, or Dajaxice), because I couldn't manage to install it properly after trying many times.
Thanks a lot!
1$First Item&2$Second Item&3$Third Item...
This information is recived at the views, as I can display it in the screen using HttpResponse. It is also reaching the html, as I can render it to the html and display it. But I fail using it at the javascript function. On the other hand, if I pass to the javascript function the same string I would get from the exe, but now I hardcode it at views.py, it worksprint "Output: " + y + "..."
?