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 7909093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:15:29+00:00 2026-06-03T12:15:29+00:00

I have a drop down list (ddlAccount) which i can choose an item from

  • 0

I have a drop down list (ddlAccount) which i can choose an item from it and do a db query in test.php to retrieve corresponding data, then output an input element with the returned data.

This is my javascript code:

function load1(){
$('#divAccountNum').load('test.php?accountInfo=' + document.getElementById('ddlAccount').value , '' ,function() {
alert('Load was performed.')}); 
}

load1 function called when i change the dropdown list items, and it takes the value of the selected option and sends it to test.php in a parameter called “accountInfo”.

my html:

  <select name="ddlAccount" id="ddlAccount" onchange="load1();">
    <option value="1"> Account1</option>
    <option value="2"> Account2</option>
    <option value="3"> Account3</option>
  </select>

  <div id="divAccountNum" >
  </div>

And test.php :

if($_GET['accountInfo'])
{
    $account = $accountDAO->load($_GET['accountInfo']); //mysql query
        //print an input holding account number as its value
    echo "<input type='text' name='txtAccountNum' id='txtAccountNum' value='".$account->accountnumber."'/>"; 
}

The problem is that nothing happened when i choose an option (nothing appear in div (divAccountNum))
Any suggestions? Thanks in advance.

Edit:
I used @thecodeparadox ‘s bit of code and it works and i found a solution for the problem that i mentioned in the comments below which is that when choosing one item from the dropdown list it shows the value in input element and loads the form again. The solution is in:
jQuery Ajax returns the whole page
So my jquery code now looks like:

$(document).ready(function(){
  $('#ddlAccount').on('change', function() {  
$.get('testJquery.php?accountInfo=' + $(this).val(), function(accountNum) {
    //console.log(accountNum);
    $('input#txtAccountNum').val(accountNum);
   });
});

And testJquery.php :

if($_GET['accountInfo'])
{
    $account = $accountDAO->load($_GET['accountInfo']);
    $accountNum = $account->accountnumber;
    echo $accountNum;
}

And at last i added input element in divAccountNum which has id=”txtAccountNum”

  • 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-03T12:15:30+00:00Added an answer on June 3, 2026 at 12:15 pm

    Though you don’t give enough info about your problem, but you can try this:

    function load1(){
      $('#ddlAccount').on('change', function() {  
        $.get('test.php?accountInfo=' + $(this).val(), function(response) {
           $('div#divAccountNum').html(response);
        }, 'html');
      });
    }
    

    NOTE:

    1. $('#ddlAccount').on('change', fires when dropdown change
    2. $.get('test.php?accountInfo=' + $(this).val().. send a get(ajax) request to test.php with value selected from drop down
    3. parameter response with in $.get() second parameter callback function is the response from the server
    4. 'html' as third parameter of $.get() for data type you return, as you return a html so it is html.

    for more info read:

    change()

    $.get()

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

Sidebar

Related Questions

I have a drop down list that gets its data from a php web
I have a drop-down list containing classifications of currencies which can be instantiated as
I have a drop-down list which is generated based on the following sql query:
I have a drop-down list which gathers data from the database and a textbox
I have a drop down list where users can select a theme for the
I have a drop down list which is dynamically generated using ajax on page
I have a drop-down list which causes a text-area to populate with different text
I have a drop down list , in which i have list of browsers
Basically I have a drop down list which is populated with text and values
Using the example at the following URL: http://www.kavoir.com/2009/02/php-drop-down-list.html How can I have that drop

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.