Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7719371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:24:01+00:00 2026-06-01T03:24:01+00:00

Thanks for the response, @ManselUK Fixed this part with finding values(below) But , when

  • 0

Thanks for the response, @ManselUK


Fixed this part with finding values(below)

But, when I SELECT a value, it doesnt set the value of the hidden element, why not?

I’m getting error: Uncaught TypeError: Cannot set property 'value' of null when I select a value from autocomplete..

Php code which is called upon entering 5 characters:

   try{

        $occupation = mysql_real_escape_string($_GET['term2']); //////
        echo 'term 2 '. $occupation;
        ///////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////
        $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );  
        $sth = $dbh->prepare(
        'SELECT occupID, occupVal From Occupation WHERE occupVal = ?');
        $sth->bindParam(1, $occupation);
        $sth->execute();
        $jsonArray = array();
        while ($result = $sth->fetch(PDO::FETCH_ASSOC)) {
         $jsonArray[] = array(
              'label' => $result['occupVal'], 
              'value' => $result['occupVal']."|".$result['occupID']); 
        }

        print json_encode($jsonArray); // json encode that array
    } // try   

the catch{} block of code, will send errors to a file, but that file has no errors in it.

The HTML Form Input:

<label for="occup">What is your occupation? <br /></label>
                            <div class="ui-widget">
                                <input id="occup" type="text"  name="term2" value="e.g. Carpenter, Developer, etc" onFocus="clearText(this)" /><br />
                                <input type="hidden" id="actualOccup" name="actualOccupval" value="" />

The JS that is called upon entering something:

    <script type="text/javascript">
    $(document).ready(function()
    {
        // Zipcode Field
        $('input#zip').autocomplete({

            dataType: "json",
            source: "../src/php/registration/getFanLoc.php",
            minLength: 4,
            select: function(event, args){
                event.preventDefault();
                var joinedValues = args.item.value;
                var id = joinedValues.split("|")[0];
                var cityAndState= joinedValues.split("|")[1];
                document.getElementById('actualZip').value = cityAndState ; 
                document.getElementById('zip').value = id;
            }
        });
        // Occupation Field
        $('input#occup').autocomplete({
        source: function(request, response) {
        $.getJSON("../src/php/registration/getFanOccupation.php", { term2: request.term }, response);
        },
        minLength: 5,
        select: function(event, args){
        event.preventDefault();
        var joinedValues = args.item.value;
        var id = joinedValues.split("|")[0];
        var occupValAndId= joinedValues.split("|")[1];
        $('#actualOccupval').val(occupValAndId); 
        $('#occup').val(id);
    }
});
    });
    </script>

I’ve tried debugging:

– Check error log for this file. (no errors)
– Check the SELECT query , the value for occupVal in database is a VARCHAR, in SQL the value is found by doing occupVal = 'some val here'; does jQuery need these quotes?
– if I access getFanOccupation.php?term2=Computer Programmer directly it outputs: term 2 Computer Programmer[{"label":"Computer Programmer","value":"Computer Programmer|183"}]
– Which is RIGHT, the problem is if I get Computer Programmer value and paste directly in input, or even start to write it, it

Fixed JS: – this code works, was select wrong ID for occupation, that’s why it wasn’t showing the hidden forms field value

    $(document).ready(function()
    {
        // Zipcode Field
        $('input#zip').autocomplete({

            dataType: "json",
            source: "file1.php",
            minLength: 4,
            select: function(event, args){
                event.preventDefault();
                var joinedValues = args.item.value;
                var id = joinedValues.split("|")[0];
                var cityAndState= joinedValues.split("|")[1];
                document.getElementById('actualZip').value = cityAndState ; 
                document.getElementById('zip').value = id;
            }
        });
        // Occupation Field
        $('input#occup').autocomplete({
            source: function(request, response) {
                $.getJSON("file.php", { term2: request.term }, response);
            },
            minLength: 5,
            select: function(event, args){
                event.preventDefault();
                var joinedValues = args.item.value;
                var id = joinedValues.split("|")[0];
                var occupValAndId= joinedValues.split("|")[1];
                $('#actualOccup').val(occupValAndId); 
                $('#occup').val(id);
            }
        });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:24:02+00:00Added an answer on June 1, 2026 at 3:24 am

    Use this :

    source: function(request, response) {
       $.getJSON("../src/php/registration/getFanOccupation.php", { term2: request.term }, response);
    }
    

    on the second autocomplete. Docs for $.getJSON() here

    From the docs :

    A request object, with a single property called “term”, which refers
    to the value currently in the text input. For example, when the user
    entered “new yo” in a city field, the Autocomplete term will equal
    “new yo”.

    Full code :

    $('input#occup').autocomplete({
        source: function(request, response) {
           $.getJSON("../src/php/registration/getFanOccupation.php", { term2: request.term }, response);
        },
        minLength: 4,
        select: function(event, args){
            event.preventDefault();
            var joinedValues = args.item.value;
            var id = joinedValues.split("|")[0];
            var occupValAndId= joinedValues.split("|")[1];
            $('#actualOccupval').val(occupValAndId); 
            $('#occup').val(id);
        }
    });
    

    Note also changed document.getElementById('blah').value = to $('#blah').val() as your already using jQuery … docs for the val() method here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please if you know, make a response. thanks
Thanks to the answer on this stackoverflow question I was able to get the
Thanks for taking the time to read this. I have an unknown number of
Thanks to this question (click me!) , I have the Source property of my
SELECT student_id, section, count( * ) as total FROM raw_data r WHERE response =
This may be very basic, but I just can`t figure out what to do,
I have a table like this (MySQL 5.0.x, MyISAM): response{id, title, status, ...} (status:
So thanks to the response to my previous question , I've tried to make
Thanks for the response. Here's the problem....the Oildatasetstatusid's (5-11) are mapped to labid=4. Labid=4
Related to my earlier question (thanks for your response Cryo), I have a further

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.