views:

197

answers:

1

I need to set the value of a field in a form via JavaScript. The source of the data is from another source, via an IFRAME. I'm running this code in the onload of the ASPX page in the IFRAME:

// Get value from source
var currencyText = document.getElementById("contractValue").value;

// Convert that value to a number, stripping out non-number characters.
var currencyNumber = new Number(currencyText.replace(/[^0-9\.]+/g,""));

//  Set the value in the CRM field.
parent.crmForm.all.targetCurrencyField.DataValue = currencyNumber;

When I do this I get an message "This control only accepts numbers or null as input". What is the acceptable way to load a value into a currency field in MS CRM?

+1  A: 

Try this instead

//strip non numeric characters from currencyText
parent.crmForm.all.targetCurrencyField.DataValue = parseInt(currencyText)
Matt Dearing
That worked, though I changed it to parseFloat to make sure I captured the cents. Any idea why this works, but new Number() doesn't?
Greg McGuffey
You didn't want new Number() because that was actually creating an object. You could have done parent.crmForm.all.targetCurrencyField.DataValue = Number(currencyText) instead.
Matt Dearing