#1
  1. Lurker - in your bushes
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Location
    .be
    Posts
    494
    Rep Power
    116

    JQuery UI: autocomplete with options:selected


    Dear Devshed denizens,

    I want to use an autocomplete on an input field, and select what sort of table/data it pulls WRT the dropdown that follows it:


    html:
    PHP Code:
    <input type="text" name="quicksearch" id="quicksearch" value="Search candidates"  />
    <
    br />        
    <
    select name="quicksearch_type" id="quicksearch_type" onChange="LoadQSHiddn();">
                <
    option value="cand_id">Candidate ID</option>
                <
    option value="username">Username/Login</option>
                <
    option value="pers_id">Personal Nr</option>
                <
    option value="cname">Current Name</option>
                <
    option value="lname">Family name at birth</option>
                <
    option value="fname">First Name</option>
                <
    option value="email">Email</option>
                
            </
    select>
            <
    input type="hidden" id="hiddn_qs_type" value="cand_id" readonly />

    <
    script type="text/javascript">
    //temp function to copy the value of quicksearch_type into the value field of #hiddn_qs_type

    function LoadQSHiddn()
            {
            var 
    t_val = $('#quicksearch_type option:selected').val();
            $(
    '#hiddn_qs_type').val(t_val);    
            }

    //load autocomplete with the type selected from the dropdown (copied in the hidden field)    
    $(function() {
        $( 
    "#quicksearch" ).autocomplete({source"./inc/inc_quicksearch.cfm?filter=" +$('#hiddn_qs_type').val(),minLength2});    
        });
        
    </script> 
    My problem is that no matter what I select in the dropdown, it's always set as: cand_id (which was the selected field when the page loaded)
    Saintaw

    pending.
  2. #2
  3. Lurker - in your bushes
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Location
    .be
    Posts
    494
    Rep Power
    116
    Sorted (ugly)

    I placed the autocomplete call insite the function:

    Code:
    	function LoadQSHiddn()
    		{
    		var t_val = $('#quicksearch_type option:selected').val();
    		$('#hiddn_qs_type').val(t_val);	
    		$( "#quicksearch" ).autocomplete({source: "./inc/inc_quicksearch.cfm?filter=" +$('#hiddn_qs_type').val(),minLength: 3});
    		}
    
    	//call it by default
    	$(function() {
    	$( "#quicksearch" ).autocomplete({source: "./inc/inc_quicksearch.cfm?filter=" +$('#hiddn_qs_type').val(),minLength: 3});	
    	});
    Saintaw

    pending.

IMN logo majestic logo threadwatch logo seochat tools logo