Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Tim on Jul 05, 2009 18:52
open dhtmlx forum
combo and '&' characters

Hello,

Shown below is the sample code, amended for my DB to autocomplete a combobox.

The combo box will not load the option correctly when you have an '&' character in the field. It will work if there is a space.
Example :
'A&' - truncates to 'A'
'A &' - shows proper options


I am calling the combo like this:
    var z=dhtmlXComboFromSelect("label");
    z.enableFilteringMode(true,"labelSuggest.php",true);


labelSuggest.php:

    header("Content-type:text/xml");
    print("<?xml version=\"1.0\"?>");

$link = mysql_pconnect("xx", "xx", "xx");
$db = mysql_select_db ("xx");

    if (!isset($_GET["pos"])) $_GET["pos"]=0;

        $sql = "Select * from tblLabel";
         $res = mysql_query ($sql);
    getDataFromDB($_GET["mask"]);
    mysql_close($link);

    function getDataFromDB($mask){
        $sql = "SELECT DISTINCT label FROM tblLabel Where label like
'".mysql_real_escape_string($mask)."%'";
        $sql.= " Order By label LIMIT ". $_GET["pos"].",20";

        if ( $_GET["pos"]==0)
            print("<complete>");
        else
            print("<complete add='true'>");
        $res = mysql_query ($sql);
        if($res){
            while($row=mysql_fetch_array($res)){
                $thisLbl = $row['label'];
                print("<option value='" . urlencode($thisLbl) . "'>");
             print "<![CDATA[" . $thisLbl . "]]>";
                print("</option>");
            }
        }else{
            echo mysql_errno().": ".mysql_error()." at ".__LINE__." line in

".__FILE__." file<br>";
        }
        print("</complete>");
    }

Answer posted by Alex (support) on Jul 05, 2009 23:59

Hello,

try to use A&amp; instead of A&. For example: 

<option value=".."><![CDATA[A&amp;]]></option>

Answer posted by Tim on Jul 06, 2009 18:44

Thanks!

I used the htmlspecialchars() php function...

and that solved it!