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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:38:07+00:00 2026-06-05T09:38:07+00:00

Inside my page I have an input (Model) with a datalist attribute and a

  • 0

Inside my page I have an input (“Model”) with a datalist attribute and a select menu (“Brand”). When a user select one of the options of the datalist from the Model, it will dynamically change the options value from the Brand select menu. Both options value from Model and Brand are called from the database. This is what I code so far;

<input type="text" name="type" id="type" list="datalist1" onchange="fw();"/>

    <datalist id="datalist1">

         <?php 

      $query9 = "SELECT DISTINCT model FROM server ORDER BY model ASC";
      $result9 = mysql_query($query9);

      while($row9 = mysql_fetch_assoc($result9)) 
      {

      echo '<option value="'.$row9['model'].'">';

     }              ?>

    </datalist>

 <select name="brand" id="test2"><option value="">-- Select Brand--</option></select>

Script;

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function fw()
{
var selname = $("#type").val();  
$.ajax({ url: "getBrand.php",

    data: {"brand":brand},

    type: 'post',

    success: function(output) {      

     document.getElementById('test2').options.length = 0;

     document.getElementById('test2').options[0]=new Option(output,output);
        // document.getElementById('test2').options[1]=new Option(output,output);       
    }

 });
}

</script>   

getBrand.php

<?php
define('DB_HOST1', 'localhost');
define('DB_NAME1', 'standby');
define('DB_USER1', 'root');
define('DB_PASS1', '');
$link = mysql_connect(DB_HOST1, DB_USER1, DB_PASS1);
if(!$link)
{
    exit('Cannot connect to server "' . DB_HOST1 . '"');
}

mysql_select_db(DB_NAME1, $link) or die('Cannot use database "' . DB_NAME1 . '"');


if (isset($_POST['brand'])) {   
$selname = $_POST['brand'];

$query = "SELECT * FROM server WHERE model='$brand'";
$res = mysql_query($query);
$aBrand= array();
while($rows = mysql_fetch_assoc($res)) {

$brand= $rows['brand'];

$aBrand[] = $brand; 

echo $aBrand[0];
echo $aBrand[1];
}

}    ?>

From what I have coded, I have succesfully change the select menu dynamically but there is one problem. When there is more one data is called from getBrand.php, the ‘output’ in the select menu will combine all of the data into one line. For example, if the data is “M3000” and “M4000”, it will display as “M3000M4000”. Now, how do I split it and make it as a normal select options?

I’m still learning Javascript and I hope anyone here can guide me.

NOTE : The code only works in Firefox because of the datalist attribute

  • 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-05T09:38:10+00:00Added an answer on June 5, 2026 at 9:38 am

    Send your data from getBrand.php as

    echo implode(“;”, $aBrand);

    this will generate a string like M3000;M4000;M5000;M6000

    and in your java script code break the string into array using this code.

    StrArr = Str.split (“;”);

    here ‘Str’ is your output given by getBrand.php, and ‘StrArr’ is the array which contains your brands.

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

Sidebar

Related Questions

I have a page with user controls getting dynamically added. Inside some of these
I am attempting to have a multiple model input page where I have 4
I have a widget inside of my asp.net page from a third party. I
I have iframe inside my page for save data in database.I use validate.js to
I have a php page inside a folder on my website. I need to
i have a problem with rendering #{} inside JSF page. I'm using Mojarra 2.1.5
I have a form loading inside my page and there is a button out
I have a couple of links on my page (inside a <div id=theme-selector> )
I have an iframe where the web page inside of the iframe runs a
I have a class level price variable decalred inside a page, like this: public

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.