Your using the onblur event listener in your input element.
The problem with doing that is that the input element looses focus as soon as the div or iframe appears.
When your list appears there is no id returned until you select a value from the list.
So a null value is returned the first time.
Then if you again give the input element the focus and either enter another value or tab away from it, then the previous id will be returned, not the current value selected from the list.
To fix this problem you first need to remove the onblur event listener from the input element.
Then you add the makeRequest function call to the ajax_option_setValue function.
Something like this:
Javascript Code:
function ajax_option_setValue(e,inputObj)
{
if(!inputObj)inputObj=this;
var tmpValue = inputObj.innerHTML;
if(ajax_list_MSIE)tmpValue = inputObj.innerText;else tmpValue = inputObj.textContent;
if(!tmpValue)tmpValue = inputObj.innerHTML;
ajax_list_activeInput.value = tmpValue;
if(document.getElementById(ajax_list_activeInput.name + '_hidden'))document.getElementById(ajax_list_activeInput.name + '_hidden').value = inputObj.id;
ajax_options_hide();
makeRequest('insert.php?field_name=country&field_value=',inputObj.id);
}
If you want to return the country name instead of the id then use tmpValue instead of inputObj.id
If I understand what you want to do correctly, then this should work.
One more thing,
From what I can tell is you aren't using the hidden input element, so remove it.
And shorten the ajax_option_setValue function to this:
Javascript Code:
function ajax_option_setValue(e,inputObj)
{
if(!inputObj)inputObj=this;
var tmpValue = inputObj.innerHTML;
if(ajax_list_MSIE)tmpValue = inputObj.innerText;else tmpValue = inputObj.textContent;
ajax_list_activeInput.value = tmpValue;
ajax_options_hide();
makeRequest('insert.php?field_name=country&field_value=',inputObj.id);
}