Jump to content
oscarrpl

Calculating and saving from virtual fields in details page

Recommended Posts

<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!

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...