Hi. I have 2 text boxes in a form the user can type numbers into. I just want to add the numbers they type in together and output the answer. I'm starting off simple and will get more complicated with my calculations later. I actually have the calculations working if they are entered into a database, but we need this to work on the fly depending on what the user typed into the text boxes.
I am only able to set the text box values and output them, but I cannot get them to add together. I have some javascript that outputs what was typed into the boxes by using CFSet. Is this the way I should write this? Is there a way to condense the javascript, or do I need to separate each set of text box code out? Is there a different way to do this simple calculation with just Cold Fusion, or do I need the javascript to grab the numbers that are entered into the text boxes? Here's the code I have below. If you remove the CFset price and the output of Price, you'll see that this code outputs the X and Y text boxes. Thanks for your help.
<cfparam name="url.X" default="">
<cfparam name="url.Y" default="">
<cfoutput>
<script type="text/javascript">
var pageSubmit = '#jsStringFormat(url.X)#';
function appenX(){
document.getElementById('submitLink').href = '?X=' +
encodeURIComponent(
(pageSubmit.length?pageSubmit + ', ':'') +
document.getElementById('X').value);
}
var pageSubmit = '#jsStringFormat(url.Y)#';
function appenY(){
document.getElementById('submitLink').href = '?Y=' +
encodeURIComponent(
(pageSubmit.length?pageSubmit + ', ':'') +
document.getElementById('Y').value);
}
</script>
<cfform name="theForm" action="##" method="get">
<cfinput type ="text" name="X" id="X" value=""><br />
<cfinput type ="text" name="Y" id="Y" value="">
<input type="submit" id="submitLink" onclick="appenX();" onclick="appenY();" value="Update">
</cfform>
<cfset X = #url.X#>
<cfset Y = #url.Y#>
<cfset Price = X + Y>
#X#<br />
#Y#
#Price#
</cfoutput>
Andy