oscarrpl Posted July 25, 2016 Report Share Posted July 25, 2016 <script type="text/javascript"> function calculate(){ var pm1 = document.getElementById("cbParamVirtual3").value; var pm2 = document.getElementById("cbParamVirtual8").value; var pm3 = document.getElementById("cbParamVirtual13").value; var pm4 = document.getElementById("cbParamVirtual18").value; var pm5 = document.getElementById("cbParamVirtual23").value; var pm6 = document.getElementById("cbParamVirtual28").value; document.getElementById("EditRecordTotal").value = pm1 + pm2 + pm3 + pm4 + pm5 + pm6; } document.getElementById("Mod0EditRecord").onmouseover=calculate(); </script> There's my code, I don't know why it's not executing. I tried using the Inspect option in my browser and found this... Quote Uncaught TypeError: Cannot read property 'value' of null being called on this line var pm1 = document.getElementById("cbParamVirtual3").value; The field is not null, so I inspected the field I inspected that field and the inspector tells me the Id of that field is actually as follows: Quote cbParamVirtual3_57357e31ed233c So it seems a random set of characters is being added at the end of all my fields, making me unable to "getElementById" since I'll never know what the random set is going to be... How can I either find out that random set or stop it from being generated? Thanks! Quote Link to comment Share on other sites More sharing options...
MayMusic Posted July 25, 2016 Report Share Posted July 25, 2016 Since the ID of the field is changing on each load call it by name var pm1 = document.getElementsByName("cbParamVirtual3")[0].value; Quote Link to comment Share on other sites More sharing options...
oscarrpl Posted July 25, 2016 Author Report Share Posted July 25, 2016 Thanks for your reply. The console doesn't show any errors now, however the script doesn't seem to be assigning the value to the "Total" field... what else could I be missing? Quote Link to comment Share on other sites More sharing options...
MayMusic Posted July 25, 2016 Report Share Posted July 25, 2016 Is Total is number field? If yes then you are concatenating texts and it is not getting saved to number field. To test you can add alert for instance before: document.getElementById("EditRecordTotal").value = pm1 + pm2 + pm3 + pm4 + pm5 + pm6; add alert(pm1 + pm2 + pm3 + pm4 + pm5 + pm6); at the beginning after function add alert("Inside Function"); See if you are getting the alerts and see what values you have in Quote Link to comment Share on other sites More sharing options...
oscarrpl Posted July 26, 2016 Author Report Share Posted July 26, 2016 Ooh, the value the alert showed is "NaN" what does this mean? Quote Link to comment Share on other sites More sharing options...
MayMusic Posted July 26, 2016 Report Share Posted July 26, 2016 It means not a number you need to change your lines to: parseFloat(document.getElementById("cbParamVirtual3").value); or parseInt(document.getElementById("cbParamVirtual3").value); to convert the result to a number value. 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.