Click to See Complete Forum and Search --> : Trouble with adding numbers.. not your usual trouble though..


gtennant
January 26th, 2006, 05:59 PM
Hi,

I have a piece of code snippet, that I'd like to use to add two numbers, and what I was wondering about, is why DreamWeaver 8 is showing a portion of the code section in red? I have an idea it has to do with fields that start with numbers, but I was told be the person running the site where the form is being submitted to, that in order for my submitted form to have the fields in the order I want them, when they are received by e-mail, that I would need to put numbers in front. Otherwise first_name is 4 or 5 lines away from last_name, in the resulting e-mail message.


Here's the code:

<SCRIPT language = JavaScript>

function calculate() {
A = document.form2.17_gross_monthly.value
B = document.form2.18_other_income.value
A = Number(A)
B = Number(B)
C = (A + B)
document.form2.19_total_gross_income.value = C
}
</SCRIPT>


The ".##" portions are highlighted, by DreamWeaver 8, in red. I am assuming the script will fail because a ".##" is following the "2" in "form2", and it doesn't know that the "2" is part of the form name.

Is there a better way to add these two "number-first" fields?

Is there a better way to sort the fields before they are submitted to the form processor at: https://www.big-llc.com/formmailer/submit without having to use numbers first, on the field names?

Many thanks in advance!


Gil

wildfrog
January 26th, 2006, 06:19 PM
The ".##" portions are highlighted, by DreamWeaver 8, in red. I am assuming the script will fail because a ".##" is following the "2" in "form2", and it doesn't know that the "2" is part of the form name.According to the specification (ECMAScript, ECMA-262) an identifier shouldn't start with a number. It should start with a letter, '$', '_' or an escape sequence.

- petter

gtennant
January 26th, 2006, 06:25 PM
Okay. I kinda suspected that was the case... which leads me to my last question:

"Is there a better way to sort the fields before they are submitted to the form processor at: https://www.big-llc.com/formmailer/submit (since one cannot) use numbers first, on the field names?"


Thanks.


Gil

wildfrog
January 26th, 2006, 06:54 PM
If I remember correctly you should be able to do something like this:

A = document.form2["17_gross_monthly"].value;
- petter

gtennant
January 27th, 2006, 01:00 AM
Wildfrog, I really appreciate the assistance on this!

I made the change you suggested, but I can't tell if it's actually working. Is there a way to check and see if the value for "C" is being set correctly?

The form begins...

<form action="https://www.big-llc.com/formmailer/submit" method="post" enctype="application/x-www-form-urlencoded" name="form2" target="_blank" id="form2" onsubmit="YY_checkform('form2','9_home_status[0]','#q','2','You must select at least one Home status.' ... (FORM VALIDATION CONTINUES) ... '24_email','S','2','Please enter your e-mail address.');return document.MM_returnValue">
<input type="hidden" name="fm-to" value="me@mydomain.com"/>
<input type="hidden" name="fm-title" value="Lease Application" />
<input type="hidden" name="fm-redirect" value="http://www.mydomain.com/thankyou.html" />


This is the three fields related to the addition of numbers, in the form:


.
.
.
<input name="17_gross_monthly" type="text" class="text" id="17_gross_monthly" value="0000" size="12" maxlength="8" />
<input name="18_other_income" type="text" class="text" id="18_other_income" value="0000" size="12" maxlength="8" />
<input name="19_total_gross_income" type="text" class="text" id="19_total_gross_income" value="" maxlength="8" />
.
.
.


This last field, "19_total_gross_income", is the one to be calculated. Have I defined it correctly, or should the "hidden" property be placed in there somewhere, since it is not a field I want people to type anything into?

I have the following in the form, at the end, before the </form> tag:


<input name="Submit2" type="submit" onClick = calculate()/>


The calculate function is called on the Submit button, but when I receive the form submission by e-mail, the 19th field is empty, with no value. NOTE: mydomain.com and the e-mail address are place holders, and not the real ones.


Thanks!

Gil