Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Chris Pijl on May 13, 2009 04:47
open dhtmlx forum
dhtmlxCombo Load on click / display &-symbol in combotext

Hi again,

I'm trying to use javascript and AJAX to load my Combo, onclick.
This is actually working like this:

<select style="width:180px;" name="cmbdata" id="combo_data" size="1">
        <option value="-1">all data</option>
</select>
<script>
            var v=dhtmlXComboFromSelect("combo_data");
            v.enableFilteringMode(true);
            v.attachEvent("onOpen",function(){
                LoadData();
            });    
    </script>

//(the below section is actually above my HTMLbody of course)
<cfajaxproxy cfc="#application.stApplicationData.sComponents#.cData" jsclassname="jsDataobj" />

<script language="Javascript">
    var cfcAsAjax = new jsDataobj();
var DataLoaded= 0;

var LoadData = function() {
        cfcAsAjax.setQueryFormat("column");
        var qJSData = cfcAsAjax.getJSData();
            DataLoaded = 1;
            var CurSelection = v.getActualValue();
            v.clearAll(true);
            v.addOption(-1,'all data');

// Here comes my problem
var test = 'Rock&Roll'
// The option added below only shows 'Rock' in the combo
v.addOption(0,test);

// The option added below only shows 'Rock' in the combo
v.addOption(1,test.replace(/&/g,"\&"));

// The option added below only shows 'Rock & Roll' in the combo
v.addOption(2,test.replace(/&/g," & "));

// continue with working script
            for (var i=0; i<qJSData .ROWCOUNT; i++) {
             // loop through JSON recordset...

//This is the actual data added from the JSON recordset
             v.addOption(qJSPlangroups.DATA.ID[i],qJSPlangroups.DATA.NAME[i].replace(/&/g," & "));
            }
            v.setComboValue(CurSelection );
            v.attachEvent("onChange",function(){
                if (v.getActualValue()==v.getComboText()) //non existing option entered
             {
                 frmForm.combostatus.value='Reset';
                 v.setComboValue("<cfoutput>#form.cmbdata#</cfoutput>");
             }
             else if (frmForm.combostatus.value == 'Reset')
             {
                 frmForm.combostatus.value='';
             }
             else
             {
                 frmForm.submit();
             }
            });
            
        }

</script>

Hmmm, when I started out typing this I thought it was de JSON-data which wasn't acting like a string, so that's why I posted the entire code...
(Well I hate a waste of typing, so I'm just going to keep it there, it may be of some use to someone!)

So my only 'problem' now is that for some strange reason I can't seem to display text in my Combo like 'Rock&Roll' through a variable, because it gets cut off at the &-symbol...
Unless you add a space behind it...
Any thoughts on that?

Thanks in advance,
Chris
Answer posted by Alex (support) on May 13, 2009 05:32

Hello, 

please, use &amp; instead of &. In this case the symbol will be shown correct on the html page. 

Answer posted by Chris Pijl on May 13, 2009 05:38
Omg...
And again I'm stumped by simplicity...
Why couldn't I figure that one out :S

Well thanks for the quick response anyway!
Still hope I've helped someone with load-on-click script ;)