This question may be related to a resolved thread.
I am using an autocomplete javascript to pass channel entry titles to my form field that allows users to search for channel entries in a certain channel. Considered using one of two structures:
1) call js file stored in themes folder using “open script tag” src=“http://mysite.com/themes/js/autoCompleteTextfield.js” type=“text/javascript”>“close script tag”
or
2) insert javascript inline within template
I went with the second structure given the need to pass the channel entry titles to an array locations = new Array(). The script inline works just fine with hard coded values into the array but I can not get it to work with the channel entry “{title}” tag.
Working Inline JS script with hard coded Array values and form look like so:
<body>
"open script tag"
countries = new Array(
"value1",
"value2",
"value3",
"value4"
);
var sug = "";
var sug_disp = "";
function getLocation() {
var input = document.forms['search_form'].location.value;
var len = input.length;
sug_disp = ""; sug = "";
if (input.length) {
for (ele in countries)
{
if (countries[ele].substr(0,len).toLowerCase() == input.toLowerCase())
{
sug_disp = input + countries[ele].substr(len);
sug = countries[ele];
break;
}
}
}
document.forms['search_form'].mycountry.value = sug_disp;
if (!sug.length || input == sug_disp)
document.getElementById('sug_btn').style.display = "none";
else
document.getElementById('sug_btn').style.display = "block";
}
function setLocation() {
document.forms['search_form'].location.value = sug;
hideSug();
}
function hideSug() {
document.forms['search_form'].mycountry.value = "";
document.getElementById('sug_btn').style.display = "none";
}
"close script tag"
<div>
<form name="search_form">
<div>Search for a destination:</a>
<div>
<div>
<input type="text" name="mycountry" disabled />
</div>
<div>
<input autocomplete="off" type="text" name="location" />
</div>
<div id="sug_btn">
<a href="#">img src="http://mysite.com/images/image.gif" width="10" height="10" border="0" align="textbottom"></a>
</div>
</div>
</form>
</div>
</div>
</body>Not working modified code that tries to call channel entries:
<body>
{exp:channel:entries channel="mychannel"}
"open script tag"
countries = new Array(
"{title}",
);
same JS script above
"close script tag"
{/exp:channel:entries}
<div>
same form code as aboveHow can I make this work using this inline structure or by placing in separate JS file and passing channel entry titles somehow? Hope this helps others.