Click to See Complete Forum and Search --> : Javascript field to email


Harriet1952
12-04-2003, 02:13 AM
I am new to Javascript and need a little help, please. In a webpage form, I have calculated a field using a script and want to pass the value in this field to an email that is sent to me from the webpage. I have no problems with user-entered data being included on the email, only the field I calculate.

Pittimann
12-04-2003, 02:15 AM
Hi!

Can you please post the code??

Cheers - Pit

Harriet1952
12-04-2003, 02:22 AM
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var Temp;
setClock();
function setClock() {
Temp = "";
now = new Date();
var CurDay = now.getDay();
var CurMonth = now.getMonth();
var CurYear = now.getYear();
var CurHour = now.getHours();
var CurMinute = now.getMinutes();
var CurSecond = now.getSeconds();
now = null;
if( CurDay < 10 ) CurDay = "0" + CurDay ;
if( CurMonth < 10 ) CurMonth = "0" + CurMonth ;
CurMonth = CurMonth + 1
CurYear = CurYear - 2000
if( CurYear < 10 ) CurYear = "0" + CurYear ;
if( CurHour < 10 ) CurHour = "0" + CurHour ;
if( CurMinute < 10 ) CurMinute = "0" + CurMinute;
if( CurSecond < 10 ) CurSecond = "0" + CurSecond;
CurHour = "<FONT SIZE=2><B>" + CurYear + CurMonth + " " + CurDay + CurHour + " " + CurMinute + CurSecond + "</B>";
Temp = CurHour;
}

// End -->
</SCRIPT>

Is this what you need?

Pittimann
12-04-2003, 02:27 AM
Hi!

Sorry - not really; can you post the form including all the fields (also the field being populated with the result of your calculation)?

Cheers - Pit

Harriet1952
12-04-2003, 02:31 AM
<HTML>
<head>
<TITLE> Numerology </TITLE>
<link rel="stylesheet" type="text/css" href="mystyle.CSS">
<META NAME="generator" CONTENT="Sausage Software HotDog PageWiz">

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin

function Reset() {
document.forms[0].elements[1].value = "Enter first name here...";
document.forms[0].elements[2].value = "Enter maiden name here...";
document.forms[0].elements[3].value = "Enter married name here...";
document.forms[0].elements[1].focus();
}
function submitForm() {
if ( (isName() ) && (isBrowser()) && (isSuggestion()) ) {
if (confirm("\nYour submission is about to be sent.\n\nClick Ok to submit.\n\nClick NO to cancel."))
return true
else
return false;
}
else
return false;
}
function isName() {
var str = document.forms[0].elements[1].value;
if (str == "") {
alert("\nThe NAME field is blank.\n\nPlease enter your name.")
document.forms[0].elements[1].focus();
return false;
}
for (var i = 0; i < str.length; i++) {
var ch = str.substring(i, i + 1);
if (((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && ch != ' ') {
alert("\nThe NAME field only accepts letters & spaces.\n\nPlease re-enter your name.");
document.forms[0].elements[1].select();
document.forms[0].elements[1].focus();
return false;
}
}
return true;
}
// End -->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var Temp;
setClock();
function setClock() {
Temp = "";
now = new Date();
var CurDay = now.getDay();
var CurMonth = now.getMonth();
var CurYear = now.getYear();
var CurHour = now.getHours();
var CurMinute = now.getMinutes();
var CurSecond = now.getSeconds();
now = null;
if( CurDay < 10 ) CurDay = "0" + CurDay ;
if( CurMonth < 10 ) CurMonth = "0" + CurMonth ;
CurMonth = CurMonth + 1
CurYear = CurYear - 2000
if( CurYear < 10 ) CurYear = "0" + CurYear ;
if( CurHour < 10 ) CurHour = "0" + CurHour ;
if( CurMinute < 10 ) CurMinute = "0" + CurMinute;
if( CurSecond < 10 ) CurSecond = "0" + CurSecond;
CurHour = "<FONT SIZE=2><B>" + CurYear + CurMonth + " " + CurDay + CurHour + " " + CurMinute + CurSecond + "</B>";
Temp = CurHour;
}

// End -->
</SCRIPT>
</head>
<H1 >Numerology - The Science of Numbers</H1>

<BODY onLoad="Reset()">
<IMG SRC="COVER.JPG" WIDTH="255" HEIGHT="470" ALIGN="Left" BORDER="0" HSPACE="13" ALT="COVER.JPG - 33663 Bytes">
<FORM ENCTYPE="text/plain" METHOD='POST' ACTION='mailto:harrietv@sympac.com.au?subject=Numerology' onSubmit="return submitForm()">
<p><font color="#FF0000">Remember, first name is what most people call you in everyday life.</font>
<INPUT TYPE=HIDDEN NAME="form_information" VALUE="Tomais Norton Survey. Form created on 8/8/97">
<INPUT TYPE="text" NAME="firstname" VALUE="Enter first name here..." SIZE="25" MAXLENGTH="40">
<INPUT TYPE="text" NAME="maiden" VALUE="Enter birth surname here..." SIZE="25" MAXLENGTH="40">
<INPUT TYPE="text" NAME="married" VALUE="Enter married surname here..." SIZE="30" MAXLENGTH="40"><p>
<SELECT NAME="dd" ><option>Day of birth
<OPTION>01<OPTION>02<OPTION>03<OPTION>04<OPTION>05<OPTION>06<OPTION>07<OPTION>08
<OPTION>09<OPTION>10<OPTION>11<OPTION>12<OPTION>13<OPTION>14<OPTION>15<OPTION>16
<OPTION>17<OPTION>18<OPTION>19<OPTION>20<OPTION>21<OPTION>22<OPTION>23<OPTION>24
<OPTION>25<OPTION>26<OPTION>27<OPTION>28<OPTION>29<OPTION>30<OPTION>31
</SELECT>
<SELECT NAME="mm" ><OPTION>Month of birth
<OPTION>01<OPTION>02<OPTION>03<OPTION>04<OPTION>05<OPTION>06<OPTION>07<OPTION>08
<OPTION>09<OPTION>10<OPTION>11<OPTION>12
</SELECT>
<SELECT NAME="yy" ><OPTION>Year of birth
<OPTION>1900<OPTION>1901<OPTION>1902<OPTION>1903<OPTION>1904<OPTION>1905<OPTION>1906<OPTION>1907
<OPTION>1908<OPTION>1909<OPTION>1910<OPTION>1911<OPTION>1912<OPTION>1913<OPTION>1914<OPTION>1915
<OPTION>1916<OPTION>1917<OPTION>1918<OPTION>1919<OPTION>1920<OPTION>1921<OPTION>1922<OPTION>1923
<OPTION>1924<OPTION>1925<OPTION>1926<OPTION>1927<OPTION>1928<OPTION>1929<OPTION>1930<OPTION>1931
<OPTION>1932<OPTION>1933<OPTION>1934<OPTION>1935<OPTION>1936<OPTION>1937<OPTION>1938<OPTION>1939
<OPTION>1940<OPTION>1941<OPTION>1942<OPTION>1943<OPTION>1944<OPTION>1945<OPTION>1946<OPTION>1947
<OPTION>1948<OPTION>1949<OPTION>1950<OPTION>1951<OPTION>1952<OPTION>1953<OPTION>1954<OPTION>1955
<OPTION>1956<OPTION>1957<OPTION>1958<OPTION>1959<OPTION>1960<OPTION>1961<OPTION>1962<OPTION>1963
<OPTION>1964<OPTION>1965<OPTION>1966<OPTION>1967<OPTION>1968<OPTION>1969<OPTION>1970<OPTION>1971
<OPTION>1972<OPTION>1973<OPTION>1974<OPTION>1975<OPTION>1976<OPTION>1977<OPTION>1978<OPTION>1979
<OPTION>1980<OPTION>1981<OPTION>1982<OPTION>1983<OPTION>1984<OPTION>1985<OPTION>1986<OPTION>1987
<OPTION>1988<OPTION>1989<OPTION>1990<OPTION>1991<OPTION>1992<OPTION>1993<OPTION>1994<OPTION>1995
<OPTION>1996<OPTION>1997<OPTION>1998<OPTION>1999<OPTION>2000<OPTION>2001<OPTION>2002<OPTION>2003
</SELECT><p>
<table><tr valign="top">
<td><INPUT TYPE="text" NAME="email" VALUE="Enter email address here..." SIZE="30" MAXLENGTH="60"><font color="#FFFFFF"></font></td>
<td><font color="#FF0000">OR*</font></td>
<td><TEXTAREA NAME="snail" ROWS="5" COLS="40">Enter your snailmail address here...</TEXTAREA></td>
</tr></table>

<p>Yes, you will have to pay the <FONT COLOR="#FF3000">AUD $10*</FONT> before you are sent the analysis! Click send after noting the payment details below, then contact your participating Financial Institution to make your payment.<p>

<TABLE BGCOLOR="#ffe9bf" cellpadding=3 border=1 WIDTH="55%">
<TR><TD><IMG SRC="BPAY Vertical BW Logo.BMP" WIDTH="45" HEIGHT="60" BORDER="0" ALT="BPAY Vertical BW Logo.BMP - 17694 Bytes"></TD>
<TD>BILLER CODE: <B>1234</B><br>
REFERENCE: <SCRIPT>document.write( Temp );</SCRIPT></td>
<TD bgcolor="#FFFFFF"></td>
<td bgcolor="#FF0000"><INPUT TYPE="submit" name="form" VALUE="Send !!!"></td>
</TR>
</TABLE></FORM>
<FONT COLOR="#FF0000">* Please add AUD $1 for snailmail.</FONT>
</BODY>
</HTML>

Pittimann
12-04-2003, 02:48 AM
Hi!

The REFERENCE No. calculated by the script is not written into a form field. So the value doesn't go anywhere. You should have another input (type = hidden) and at the end of the function calculating the REFERENCE No. you should set the value of that hidden input to the content of your Temp variable...

Cheers - Pit

Harriet1952
12-04-2003, 02:52 AM
I had a hidden field there with script tag in it....wouldn't allow the script tag within hidden....what should I put in the hidden field....thank you.....

Harriet

Pittimann
12-04-2003, 03:12 AM
Hi!

Have a look at the last line of the function:

function setClock() {
Temp = "";
now = new Date();
var CurDay = now.getDay();
var CurMonth = now.getMonth();
var CurYear = now.getYear();
var CurHour = now.getHours();
var CurMinute = now.getMinutes();
var CurSecond = now.getSeconds();
now = null;
if( CurDay < 10 ) CurDay = "0" + CurDay ;
if( CurMonth < 10 ) CurMonth = "0" + CurMonth ;
CurMonth = CurMonth + 1
CurYear = CurYear - 2000
if( CurYear < 10 ) CurYear = "0" + CurYear ;
if( CurHour < 10 ) CurHour = "0" + CurHour ;
if( CurMinute < 10 ) CurMinute = "0" + CurMinute;
if( CurSecond < 10 ) CurSecond = "0" + CurSecond;
CurHour = "<FONT SIZE=2><B>" + CurYear + CurMonth + " " + CurDay + CurHour + " " + CurMinute + CurSecond + "</B>";
Temp = CurHour;
document.forms[0].NameOfNewHiddenField.value=Temp;

As you start the reset function onload of the document, you should add a line with:
setClock();
at its' end and delete the same line above your setclock function. Then the hidden field (which you have to add to the form) will have the value of Temp...

Cheers - Pit

Harriet1952
12-04-2003, 03:16 AM
Thank you Pit....that was exactly what I needed....

Cheers

Harriet