Forums

Get Autocomplete clicked value

Austre 20 Mar, 2015
I need capture the autocomplete clicked value and send it to another Ajax Event, is that possible?
GreyHead 20 Mar, 2015
HI Austre,

I think that once it's clicked then it should be set as the value of the autocomplete input so you can get it from there.

Bob
Austre 26 May, 2015
Bob,

Let me continue this topic. My project that needs Autocomplete was in standby, until today.

My form has an Autocomplete "Projeto", when i select an option from it, i need get this value to use in another Autocomplete field "Ação".
[attachment=0]joomla01.JPG[/attachment]

The Autocomplete is working fine.
[attachment=1]joomla02.JPG[/attachment]

The submit button have this jQuery code, try to catch the value from Autocomplete input field.
jQuery(document).ready(function(){
	jQuery('#button2').click(function(){
		val = jQuery('#projeto').val();
		alert(val);
	});
});


When i click on submit button, no value.
[attachment=2]joomla03.JPG[/attachment]
GreyHead 27 May, 2015
Hi Austre,

I would expect that to work, the JavaScript looks good. Can you check with your browser be developer tools to see if the auto-completer adds the value to the #projeto input?

Bob
Austre 27 May, 2015
That's the developer tools
[attachment=0]joomla04.JPG[/attachment]
GreyHead 27 May, 2015
Hi Austre,

Hmmm . . . there is no value set. Please post or PM me a link to the form so I can take a quick look.

Bob
GreyHead 28 May, 2015
Hi Austre,

You can get the value set with this
jQuery('.select2-chosen').text()
That will give - for example "Artesanato em Palhas e Fibras - 2ª fase". Does that do what you need?

Bob
Austre 28 May, 2015
Bob,

I would like to get the value, the code of this text/label cause i wanna search "childrens" and populate another Dropdown.
GreyHead 28 May, 2015
Hi Austre,

That's all that I can see in the page; I don't see the value anywhere. I'll have to take a look at the code and see if I can work out if it is available. I think that the AutoCompleter only returns the text.

Bob
Austre 28 May, 2015
True,

I got the code from my database, search in the page with no success. I configured the button to submit form and debugger didn't show the value from field "projeto". Wierd, i remmember once a try that's appear.
[attachment=0]joomla05.JPG[/attachment]

Event code for field "projeto" Autocomplete
$search = JRequest::getString('tag', '', 'get');
$return = "";
$anoAtual = date("Y");

if($search!="" && strlen($search)>2){
	$lstRes = array();
	$sql = "exec ATEND_RecSolucaoBrasilMaisPorPalavraChave @Ano = N'$anoAtual', @PalavraChave = N'$search', @PartePalavraChave = N'0', @CodSebrae = N'0', @IndParceiro = N'N'";
	$conn = mssql_connect("myServer", "myUsr", "myPwd");
	$bco = mssql_select_db("myDB", $conn);
	$result = mssql_query($sql,$conn);
	
	while($row=mssql_fetch_array($result,MSSQL_ASSOC)){
			$lstRes[] = array('id' => $row["CODSOL"], 'text' => utf8_encode($row["TITSOL"]));
	}
	
	$return = json_encode($lstRes);
}
echo $return;
This topic is locked and no more replies can be posted.