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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:54:52+00:00 2026-06-08T23:54:52+00:00

I have a PHP page that I’m using JavaScript with to update dropdown lists

  • 0

I have a PHP page that I’m using JavaScript with to update dropdown lists based on MySQL results. My problem is that when I pass a customer name via JavaScript variable it cuts off at the first white space. For example: “Home Depot” would show up as “Home” or “The Home Store” shows up as “The”. In order to execute a proper query I would like for the whole string to be passed.

Here is the relevant code from my form:

    function getXMLHTTP() { //function to return the xml http object
        var xmlhttp=false;  
        try{
            xmlhttp=new XMLHttpRequest();
        }
        catch(e)    {       
            try{            
                xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e){
                try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e1){
                    xmlhttp=false;
                }
            }
        }

        return xmlhttp;
      }


    function getCustCont(cID)
    {
    var strURL="Includes/cdd.php?custid="+cID;
    var req = getXMLHTTP();
    if (req)
    {
      req.onreadystatechange = function()
      {
       if (req.readyState == 4)
       {
     // only if "OK"
     if (req.status == 200)
          {
        document.getElementById('Contdiv').innerHTML=req.responseText;
     } else {
        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
      }
        }
       }
    req.open("GET", strURL, true);
    req.send(null);
    }

//VARIABLES DEFINED AND START OF FORM

    <td width="60%">

    <select name="Customer" onchange="getCustCont(this.value)">
    <option value="SAC">Select Customer</option>
    <?php
    $i=0;
    while ($i < $num) {
    $Name=mysql_result($result,$i,"Name");

    echo "<option value=$Name>$Name</option>";
    $i++;
    }       
    ?>  

    </select>
    </td>

the cdd.php file includes the following:

  <? 
    $Cust_ID = $_GET['custid'];
    include('../Includes/TrackingDB.php');

    mysql_connect($dbhost,$dbuser,$dbpass) or die('Error connecting to mysql');
    mysql_select_db($dbdb) or die('Error connecting to database');

    $query="SELECT t1.ContName FROM Cust_Contacts t1 INNER JOIN Customer_Listing t2 ON t1.Cust_ID = t1.Cust_ID WHERE t2.Name = '$Cust_ID'";
    $result=mysql_query($query);

    mysql_close();

    echo var_dump($Cust_ID); //I added this solely for the purposes of trouble shooting this issue. This is where I am seeing the truncated string.

    ?>
    <select name="Cust_Buyer" onchange="getCity(<?=$country?>,this.value)">
    <? while($row=mysql_fetch_array($result)) { ?>
    <option value="<?=$row['ContName']?>"><?=$row['ContName']?></option>
    <? } ?>
    </select>

Again, within the cdd.php file the string truncates at white space.

  • 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-08T23:54:54+00:00Added an answer on June 8, 2026 at 11:54 pm

    encode cID

    var strURL="Includes/cdd.php?custid="+encodeURIComponent(cID);
    

    and surround the value with quotes:

    echo "<option value='$Name'>$Name</option>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php page that pulls data from a mysql database based on
I'm new to javascript, my problem is effectively: I have a php page that
I have a PHP page that outputs the results of a MySQL query. each
I have a PHP page that displays the results of a mysql query. each
I have a PHP page that loads external content using other PHP files. I'm
I have a simple php page that displays data from a mysql database. I
I have a PHP / Javascript page that automatically logs a user into different
I have a php page that displays rows from a mysql db as a
I have a PHP page that allows people to run htpasswd to update their
I have a PHP page that is reading text stored in a MYSQL database

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.