T-Bone
Posts: 2
|
Posted: 03/24/2004, 5:32 AM |
|
I am trying to add some values of fields together before the user submits the form. I have it kinda working using the On Change statement, but when I use the + symbol it treats the fields as text and appends the two numbers together.
Like 1+ 1 should be 2, but it puts 11. All the other math symbols ( - / * )work correctly and do the proper math.
I have the fields set as Data Type = Float and Format = 0.00
Here is the On Change code:
//page_Tonnage_tonnage_LF_inner_OnChange @7-E7384138
function page_Tonnage_tonnage_LF_inner_OnChange()
{
var result;
//End page_Tonnage_tonnage_LF_inner_OnChange
//Custom Code @13-2A29BDB7
// -------------------------
document.forms.Tonnage.total_tonnage_inner.value = document.forms.Tonnage.tonnage_LF_inner.value + document.forms.Tonnage.tonnage_LR_inner.value ;
// -------------------------
//End Custom Code
//Close page_Tonnage_tonnage_LF_inner_OnChange @7-BC33A33A
return result;
}
//End Close page_Tonnage_tonnage_LF_inner_OnChange
//page_Tonnage_Button_Delete_OnClick @5-3FE9263C
function page_Tonnage_Button_Delete_OnClick()
{
disableValidation = true;
}
//End page_Tonnage_Button_Delete_OnClick
//bind_events @1-31DF0DA8
function bind_events() {
if (document.forms["Tonnage"]) check_and_bind('document.forms["Tonnage"].tonnage_LF_inner','onchange',page_Tonnage_tonnage_LF_inner_OnChange);
if (document.forms["Tonnage"]) check_and_bind('document.forms["Tonnage"].Button_Delete','onclick',page_Tonnage_Button_Delete_OnClick);
forms_onload();
}
//End bind_events
Thanks
Tim
|
|
|
peterr
Posts: 5971
|
Posted: 03/24/2004, 6:01 PM |
|
According to the examples at http://www.w3schools.com/js/js_operators.asp looks like your values are treated as text instead of numbers.
You may need to find a JavaScript function that converts text to numeric values.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
T-Bone
Posts: 2
|
Posted: 03/25/2004, 4:36 AM |
|
Thanks Peter,
I also submitted a ticket to your support department and they gave me a solution, it is exactly as you said. I needed to convert it to a number. Thier suggestion was the following for anyone else needing this.
document.forms.Tonnage.total_tonnage_inner.value = eval(document.forms.Tonnage.tonnage_LF_inner.value) + eval(document.forms.Tonnage.tonnage_LR_inner.value) ;
|
|
|
Marc
|
Posted: 09/14/2004, 8:57 AM |
|
I am trying the same thing..I always get a message that document.forms.PartsTotal.Total.Value is null or not an object. I have set a default value to "1" to eliminate the null portion and i still get the same message.
|
|
|
|