Changing cfform values with javascript for dynamic bind output
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>
</cfcomponen开发者_StackOverflow社区t>
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.
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');
}
精彩评论