mdupras Posted July 7, 2009 Report Share Posted July 7, 2009 Hi all -- I have an input form datapage that uses JavaScript to perform two functions to insert data into hidden fields in the table. One function grabs the text from one of the input fields and duplicates it in a hidden field. The other function performs a calculation on two numbers from two input fields to get an average, and inserts that average into a hidden field. This datapage has worked flawlessly for months, but suddenly today, those two functions stopped working. In the first function, instead of the duplicated text, I get "NaN" inserted in the hidden field. In the other function, nothing at all is inserted in the hidden field -- it's left blank. I've made no changes to either the datapage or the related tables. Here are the JavaScript functions, FWIW -- but again, these have been working fine for months: <script language="javascript" type="text/javascript"> function calculate () { var loE = parseFloat(document.getElementById('caspioform').InsertRecorddine_entreeLow.value); var hiE = parseFloat(document.getElementById('caspioform').InsertRecorddine_entreeHigh.value); var avgE = (loE + hiE)/2; var avgR = avgE.toFixed(2); document.getElementById('caspioform').InsertRecorddine_entreeAvg.value = avgR; } document.getElementById('caspioform').onsubmit = calculate; function addName() { var restName = parseFloat(document.getElementById('caspioform').InsertRecorddine_name.value); document.getElementById('caspioform').InsertRecorddine_nameSearch.value = restName; } document.getElementById('caspioform').onsubmit = addName; </script> I've tried this on both Mac and PC, in both Firefox and IE, with the same results. I've also used the direct datapage URL, so it doesn't seem to be anything on the web page the datapage is embedded in. Anyone have an idea why this would suddenly stop working? Thanks! -- Mike Quote Link to comment Share on other sites More sharing options...
MeghaJ Posted July 8, 2009 Report Share Posted July 8, 2009 Hi Mike, I think there is a small error in your javacript code. In the addName function you are doing parseFloat to a text field and hence you are getting error NaN(not a number) error. Also onSubmit you are calling two functions separately, so only the one called last(in this case addName) is being executed. So instead of calling them separately, call the first function calculate() in the second function. Try this. <script language="javascript" type="text/javascript"> function calculate () { var loE = parseFloat(document.getElementById('caspioform').InsertRecorddine_entreeLow.value); var hiE = parseFloat(document.getElementById('caspioform').InsertRecorddine_entreeHigh.value); var avgE = (loE + hiE)/2; var avgR = avgE.toFixed(2); document.getElementById('caspioform').InsertRecorddine_entreeAvg.value = avgR; return; } //document.getElementById('caspioform').onsubmit = calculate; function addName() { calculate(); var restName = document.getElementById('caspioform').InsertRecorddine_name.value; document.getElementById('caspioform').InsertRecorddine_nameSearch.value = restName; } document.getElementById('caspioform').onsubmit = addName; </script> Hope this helps. Megha Quote Link to comment Share on other sites More sharing options...
mdupras Posted July 9, 2009 Author Report Share Posted July 9, 2009 Thank you! Those fixes did the trick! I'm puzzled though why it had been working previously. Initially I only had the first function, and it worked fine for some time. I added the second function later and did a few entries with success -- at least, I thought I did ... At any rate, it's working now, and I learned something about parseFloat and onSubmit! -- Mike Quote Link to comment Share on other sites More sharing options...
chumkirebzi Posted September 4 Report Share Posted September 4 Hi Everyone! Just want to share the following links that may help in coding Javascript. Caspio its own event handlers and script examples! https://howto.caspio.com/datapages/ajax-loading/#:~:text=on this page.-,Caspio Event Handlers,-Caspio provides built The forums also has a JS Guide for the elements to use: Good luck! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.