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

  • SEARCH
  • Home
  • 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 7920501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:14:33+00:00 2026-06-03T16:14:33+00:00

The program is supposed to be a live search using php and javascript… where

  • 0

The program is supposed to be a live search using php and javascript… where as you type it searches below. I just recently started learning javascript so sorry if my knowledge is limited…

$(document).ready(function () {
    $('#results').append('<p>Started</p>');
    var getText = (function () {
        return document.getElementById('year').value;
    });
    var text = getText;
    var getText1 = (function () {
        return document.getElementById('class').value;
    });
    var text1 = getText1;
    setInterval(function () {
        var newText = getText;
        var newText1 = getText1;
        var loading = "search.php?year=" + newText + "&class=" + newText1;
        $('#results').append(newText1);
        if (text !== newText || text1 !== newText1) {
            $('#results').load(loading);
            $('#results').append('somethinghappened');
        };
        text = newText;
        text1 = newText1;
    }, 100);
});

so it works fine when i append newText1, however if i try to append “loading” it returns:

search.php?year=function () { return document.getElementById(“year”).value; }&class=function () { return document.getElementById(“class”).value; }

Can anyone explain what the difference between the two cases is and why a difference occurs? and possibly how to fix it so that it loads the correct URL

i searched and found: JavaScript: When assigning an anonymous function to a variable, function return value is not passed, rather the function as a string however didn’t quite understand completely what it meant by passing two arguments, and when i tried to do something similar, it didn’t work as expected…

Any help is appreciated and thanks in advance.

  • 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-03T16:14:35+00:00Added an answer on June 3, 2026 at 4:14 pm
    var newText = getText;
    var newText1 = getText1;
    

    You are assigning the functions getText and getText1 to the variables instead of executing them and assigning their return values. Try this instead:

    var newText = getText();
    var newText1 = getText1();
    

    Or just:

    var newText = document.getElementById('year').value;
    var newText1 = document.getElementById('class').value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am supposed to write a program in JavaScript to find all the anagrams
Just a simple program to get used to pointers. The program is supposed to
This program is supposed to calculate the number of degrees below 60 on a
This program is supposed to judge the height of multiple buildings by the type
The program is supposed to take a file, say data.dat, filled with a list
My program is supposed to read a text document with a bunch of numbers
This program is supposed to determine how many units are stored in the value
I have a program that is supposed to interact with a web server and
I have a small program that's supposed to sample some value from a device
So I'm making a program which is supposed to print a horizontal histogram of

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.