I have a div class like this and want to call setlocation function which will set the value of the state in the text box
<div class="overview over_widt">
<ul>
<li class="auto" title="All India"></li>
{% for state_obj in state_list %}
<li name="state" class="auto" title="{{state_obj.name}}"><a href="#{{state_obj.id}}" onclick=javascript:setlocation("{{state_obj.name}}")> {{ state_obj.name }}</a></li>
{% endfor %}
</ul>
my java script function
function setlocation(name){
//alert(name);
$('#id_autocomplete').val(name);
document.getElementById('city_state').style.display="none"
}
and my textbox
<input type="text" class="text2" name="location" id="id_autocomplete" placeholder="Enter Location" onfocus="show_div();" onkeyup="div_autocomplete()"/>
The problem is I have some states which have "whitespaces" in them and passing those parameters is creating a problem . I tried passing the object also like
onclick=javascript:setlocation("{{state_obj}}")
but this also doesnt work.
encodeURIComponentto encode the string and pass that to setlocation.javascript:label is completely unnecessary there.