Coldfusion Populate form with dropdown selection using ajax

后端 未结 3 1117
感动是毒
感动是毒 2021-01-25 19:52

So I have a project that\'s using ColdFusion and it has a form with a dropdown.

See example: http://jsfiddle.net/mwoods98/KXmNK/

What I need to

3条回答
  •  被撕碎了的回忆
    2021-01-25 20:18

    If you are using jQuery you can use the ajax function built into jquery to call to the CFC and return the result and populate the fields. BTW if you want to do this putting IDs on the fields will be VERY helpful.

    $.ajax({
        type: 'get',
        url: 'pathToMy.cfc',
        data: {method:'getNameAddressAndNumberFromID'
            , myID : valueOfItemSelectedInDropDown
            },
        dataType: 'json',
        async: false,
        success: function(result){
             $('#myNameInput').val(result.NAME);
             $('#myNameInput').val(result.ADDRESS);
             $('#myNameInput').val(result.NUMBER);
            }
        }); 
    

    Assume you have a CFC named 'pathToMy.cfc' with a method of 'getNameAddressAndNumberFromID' and you have an ID on the inputs like Name:

    
    

    the result of the method could return the name, address and number from a query. Returning this info as JSON will be really helpful.

    This should get you on the right track, good luck.

提交回复
热议问题