admin管理员组文章数量:1022560
Im trying to pass the unique database session id through cfm pages but cannot seem to get it working. Page 1 has the record id, im trying to save in numSession in the recordclick() function and pass it in the next page, where I use it in my query, but its not working.
Heres a rough outline of what im doing:
Page 1:
<CFQUERY datasource = "database1" result = "result">
insert into user
set
blah blah
</cfquery>
<html>
<head>
<title>page1</title>
<script type="text/javascript">
function recordClick(imageid)
{
document.getElementById("numSend").value = document.getElementById("numSend").value + imageid;
document.getElementById("numSession").value = result.generated_key;
}
</script>
</head>
<body>
<FORM action="page2.cfm" method="post">
<img src="1.png" NAME="num1" onclick="recordClick(1)"
width="100px"
height="100px">
<div name="num1" id="num1"></div>
<input type="hidden" id="numSend" name="numSend" />
<input type ="hidden" id = "numSession" name ="numSession" />
<input type="submit" value="Done" />
</form>
</body>
</html>
--------------------------------------
<cfoutput>
The ID of the row I just inserted was "#numSession#"
</cfoutput>
<CFQUERY datasource = "database1">
update user
set
pin = "#numSend#"
where id= "#numSession#"
</cfquery>
Im trying to pass the unique database session id through cfm pages but cannot seem to get it working. Page 1 has the record id, im trying to save in numSession in the recordclick() function and pass it in the next page, where I use it in my query, but its not working.
Heres a rough outline of what im doing:
Page 1:
<CFQUERY datasource = "database1" result = "result">
insert into user
set
blah blah
</cfquery>
<html>
<head>
<title>page1</title>
<script type="text/javascript">
function recordClick(imageid)
{
document.getElementById("numSend").value = document.getElementById("numSend").value + imageid;
document.getElementById("numSession").value = result.generated_key;
}
</script>
</head>
<body>
<FORM action="page2.cfm" method="post">
<img src="1.png" NAME="num1" onclick="recordClick(1)"
width="100px"
height="100px">
<div name="num1" id="num1"></div>
<input type="hidden" id="numSend" name="numSend" />
<input type ="hidden" id = "numSession" name ="numSession" />
<input type="submit" value="Done" />
</form>
</body>
</html>
--------------------------------------
<cfoutput>
The ID of the row I just inserted was "#numSession#"
</cfoutput>
<CFQUERY datasource = "database1">
update user
set
pin = "#numSend#"
where id= "#numSession#"
</cfquery>
Share
Improve this question
edited May 1, 2019 at 23:11
Machavity♦
31.7k27 gold badges95 silver badges105 bronze badges
asked Feb 23, 2012 at 15:10
user1228554user1228554
831 silver badge6 bronze badges
1 Answer
Reset to default 6ColdFusion is executed on the server, JavaScript is executed on the client. Your JS has no idea what result
is.
You need to use ColdFusion's ToScript()
function.
Description
Creates a JavaScript or ActionScript expression that assigns the value of a ColdFusion variable to a JavaScript or ActionScript variable. This function can convert ColdFusion strings, numbers, arrays, structures, and queries to JavaScript or ActionScript syntax that defines equivalent variables and values.
Here's an example, taken from the docs:
<cfset thisString="hello world">
<script type="text/javascript" language="JavaScript">
<cfoutput>
var #ToScript(thisString, "jsVar")#;
</cfoutput>
</script>
Your code (corrected):
function recordClick(imageid)
{
var <cfoutput>#ToScript(result.generated_key, "generated_key")#;</cfoutput>
var objNumSend = document.getElementById("numSend");
objNumSend.value = objNumSend.value + imageid;
document.getElementById("numSession").value = generated_key;
}
Im trying to pass the unique database session id through cfm pages but cannot seem to get it working. Page 1 has the record id, im trying to save in numSession in the recordclick() function and pass it in the next page, where I use it in my query, but its not working.
Heres a rough outline of what im doing:
Page 1:
<CFQUERY datasource = "database1" result = "result">
insert into user
set
blah blah
</cfquery>
<html>
<head>
<title>page1</title>
<script type="text/javascript">
function recordClick(imageid)
{
document.getElementById("numSend").value = document.getElementById("numSend").value + imageid;
document.getElementById("numSession").value = result.generated_key;
}
</script>
</head>
<body>
<FORM action="page2.cfm" method="post">
<img src="1.png" NAME="num1" onclick="recordClick(1)"
width="100px"
height="100px">
<div name="num1" id="num1"></div>
<input type="hidden" id="numSend" name="numSend" />
<input type ="hidden" id = "numSession" name ="numSession" />
<input type="submit" value="Done" />
</form>
</body>
</html>
--------------------------------------
<cfoutput>
The ID of the row I just inserted was "#numSession#"
</cfoutput>
<CFQUERY datasource = "database1">
update user
set
pin = "#numSend#"
where id= "#numSession#"
</cfquery>
Im trying to pass the unique database session id through cfm pages but cannot seem to get it working. Page 1 has the record id, im trying to save in numSession in the recordclick() function and pass it in the next page, where I use it in my query, but its not working.
Heres a rough outline of what im doing:
Page 1:
<CFQUERY datasource = "database1" result = "result">
insert into user
set
blah blah
</cfquery>
<html>
<head>
<title>page1</title>
<script type="text/javascript">
function recordClick(imageid)
{
document.getElementById("numSend").value = document.getElementById("numSend").value + imageid;
document.getElementById("numSession").value = result.generated_key;
}
</script>
</head>
<body>
<FORM action="page2.cfm" method="post">
<img src="1.png" NAME="num1" onclick="recordClick(1)"
width="100px"
height="100px">
<div name="num1" id="num1"></div>
<input type="hidden" id="numSend" name="numSend" />
<input type ="hidden" id = "numSession" name ="numSession" />
<input type="submit" value="Done" />
</form>
</body>
</html>
--------------------------------------
<cfoutput>
The ID of the row I just inserted was "#numSession#"
</cfoutput>
<CFQUERY datasource = "database1">
update user
set
pin = "#numSend#"
where id= "#numSession#"
</cfquery>
Share
Improve this question
edited May 1, 2019 at 23:11
Machavity♦
31.7k27 gold badges95 silver badges105 bronze badges
asked Feb 23, 2012 at 15:10
user1228554user1228554
831 silver badge6 bronze badges
1 Answer
Reset to default 6ColdFusion is executed on the server, JavaScript is executed on the client. Your JS has no idea what result
is.
You need to use ColdFusion's ToScript()
function.
Description
Creates a JavaScript or ActionScript expression that assigns the value of a ColdFusion variable to a JavaScript or ActionScript variable. This function can convert ColdFusion strings, numbers, arrays, structures, and queries to JavaScript or ActionScript syntax that defines equivalent variables and values.
Here's an example, taken from the docs:
<cfset thisString="hello world">
<script type="text/javascript" language="JavaScript">
<cfoutput>
var #ToScript(thisString, "jsVar")#;
</cfoutput>
</script>
Your code (corrected):
function recordClick(imageid)
{
var <cfoutput>#ToScript(result.generated_key, "generated_key")#;</cfoutput>
var objNumSend = document.getElementById("numSend");
objNumSend.value = objNumSend.value + imageid;
document.getElementById("numSession").value = generated_key;
}
本文标签: javascriptSimple coldfusion pass record id to JS functionStack Overflow
版权声明:本文标题:javascript - Simple coldfusion pass record id to JS function? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745477717a2152398.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论