Changing cfform values with javascript for dynamic bind output

别等时光非礼了梦想. 提交于 2019-12-24 10:48:36

问题


CFM

<html>
<head>
<title>Test Page</title>
<script type="text/javascript">
    function toggleV(value){
        document.getElementById('blah').value = value;
    }
</script>
</head>
<body>
<cfform name="coolfrm">
    <cfinput type="hidden" name="blah" id="blah" value="default">
    <a onclick="toggleV('anothervalue')" style="cursor:pointer;">click Me</a>
</cfform>

<cfdiv bind="cfc:TestCFC.func({coolfrm:blah})"></cfdiv>

</body>
</html>

CFC

<cfcomponent>
    <cfscript>
        remote function func(simpleString){
            return simpleString;
        }
    </cfscript>
</cfcomponent>

What I expect this code to do is change the text in the cfdiv from "default" to "anothervalue".

This doesn't work the way I think it should, and I would like to know why.


回答1:


By definition from: http://www.w3.org/TR/html4/interact/scripts.html

The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus.

The change event isn't firing correctly when you modify the field programmatically.

Solve this by changing the JavaScript function slightly:

function toggleV(value){
    document.getElementById('blah').value = value;
    ColdFusion.Event.callBindHandlers('blah',null,'change');
}


来源:https://stackoverflow.com/questions/7652136/changing-cfform-values-with-javascript-for-dynamic-bind-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!