[Javascript] confusing ....

Rodney Myers rmyers at i-way.co.uk
Wed Mar 28 03:36:46 CST 2001


Andreas,

Javascript can be really confusing!

The msg() function need only be called once using the onsubmit event.
The onchange handlers in each field were not required, but interestingly
they passed the form object  - msg(this.form) - except that you did not
receive it in your version and so had to define the form object
explicitly, which makes more work.

As far as the reception of the form object in 
function msg(form) 
there is no big deal about calling the parameter/argument 'form', it
could be called anything. 
function msg(Rodney) for example

Generally the var name form is used simply to remind us of what it is.
Compare that with the use of this.form in an input as you did (correctly
defining the form object) where this.Rodney for example would NOT do,
while
function msg(Rodney) 
would be fine, though confusing since the name Rodney does nothing to
remind us of what the variable represents.


These links may help a bit
http://www.builder.com/Authoring/MoreStupid/ss05.html
http://www.winterstorm.ca/mailto.html

For a slightly neater message you could use a second form
This link contains a copyright script that does that and which may help.
It also creates a confirmation in a new window.
http://home.earthlink.net/~jeffreyfarkas/mailform.html

Try this :

<html><head>
<title>Mail Form</title>
<SCRIPT LANGUAGE="JavaScript">
function msg(form) {
mailtoandsubject = "mailto:" + listvalue(form.mailtoperson);
mailtoandsubject+= '?cc=' + listvalue(form.mailtopersonCC);
mailtoandsubject+= '&bcc=email at email.de';
mailtoandsubject+= '&subject=' + form.subject.value;
form.action  = mailtoandsubject;
return(true);
}

function listvalue(List){
return(List.options[List.selectedIndex].value);
}

</SCRIPT>
</head>
<body text='#000000' bgcolor='#ffffff'>
<FORM NAME="mailer" method="post" enctype="text/plain" ACTION=""
onSubmit="return(msg(this));">
<TABLE BORDER=0>
  <TR VALIGN="top">
 <TD>Recipient 1:</TD>
 <TD><SELECT NAME="mailtoperson">
  <OPTION VALUE="">-- Select --
  <OPTION VALUE="akrite at ginko.de">Ginko
  <OPTION VALUE="akrite at t-online.de"> T-online.de
  <OPTION VALUE="krite at 3dfactory.de">3D factory
     </SELECT>
 </TD>
  </TR>
<TR VALIGN="top">
 <TD>Recipient 2:</TD>
 <TD><SELECT NAME="mailtopersonCC">
  <OPTION VALUE="">-- Select --
  <OPTION VALUE="akrite at ginko.de">Ginko
  <OPTION VALUE="akrite at t-online.de">T-online.de
  <OPTION VALUE="krite at 3dfactory.de">3D factory
     </SELECT>
 </TD>
  <TR VALIGN="top">
 <TD>Subject:</TD>
 <TD><INPUT TYPE="text" SIZE=45 NAME="subject"></TD>
  </TR>
  <TR VALIGN="top">
 <TD>Message:</TD>
 <TD><TEXTAREA NAME="message" COLS=45 ROWS=5 WRAP="virtual"
OnChange="msg(this.form)"></TEXTAREA></TD>
  </TR>
  <TR>
 <TD> </TD>
 <TD><INPUT TYPE="submit" VALUE="Send Message">
 <INPUT TYPE="reset" VALUE="Reset"></TD>
  </TR>
</TABLE>
</FORM>

</body></html>


hth

Rodney

Andreas Krite wrote:
> 
> Hiya,
> 
> I'm not really new to this list and hope that someone could help me finding the right way.
> I like to build a mail-form where you can choose via drop-down a recipient 1 and a recipient 2 - the example listed below is not working :-(( and I'm not experienced enough to find the error.
> 
> Thanks in advance
> 
> regards
> Andreas
> ********************************************************************
> <FORM NAME="mailer" METHOD="post" ACTION="" ENCTYPE="text/plain"
> onSubmit="(document.mailer.action += mailtoandsubject)">
> <TABLE BORDER=0>
>   <TR VALIGN="top">
>  <TD>Recipient 1:</TD>
>  <TD><SELECT NAME="mailtoperson" onChange="msg(this.form)">
>   <OPTION VALUE="">-- Select --
>   <OPTION VALUE="akrite at ginko.de">Ginko
>   <OPTION VALUE="akrite at t-online.de"> T-online.de
>   <OPTION VALUE="krite at 3dfactory.de">3D factory
>      </SELECT>
>  </TD>
>   </TR>
> <TR VALIGN="top">
>  <TD>Recipient 2:</TD>
>  <TD><SELECT NAME="mailtopersonCC" onChange="msg(this.form)">
>   <OPTION VALUE="">-- Select --
>   <OPTION VALUE="akrite at ginko.de">Ginko
>   <OPTION VALUE="akrite at t-online.de">T-online.de
>   <OPTION VALUE="krite at 3dfactory.de">3D factory
>      </SELECT>
>  </TD>
>   <TR VALIGN="top">
>  <TD>Subject:</TD>
>  <TD><INPUT TYPE="text" SIZE=45 NAME="subject" onChange="msg(this.form)"></TD>
>   </TR>
>   <TR VALIGN="top">
>  <TD>Message:</TD>
>  <TD><TEXTAREA NAME="message" COLS=45 ROWS=5 WRAP="virtual" OnChange="msg(this.form)"></TEXTAREA></TD>
>   </TR>
>   <TR>
>  <TD> </TD>
>  <TD><INPUT TYPE="submit" VALUE="Send Message">
>  <INPUT TYPE="reset" VALUE="Reset"></TD>
>   </TR>
> </TABLE>
> </FORM>
> 
> <SCRIPT LANGUAGE="JavaScript">
> function msg() {
> document.mailer.action = "mailto:"
> mailtoandsubject = ((document.mailer.mailtoperson.options[document.mailer.mailtoperson.selectedIndex].value)
>  + '&CC=' + (document.mailer.mailtopersonCC.options[document.mailer.mailtopersonCC.selectedIndex].value)
>  + '&BCC=email at email.de'
>  + '?subject=' + document.mailer.subject.value);
> }
> </SCRIPT>
> ************************************************************************************************************
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> http://www.LaTech.edu/mailman/listinfo/javascript

-- 
Shop at ssistant Add-ons and Developer Workshops
http://www.aflyingstart.net/addons/
STILL PLACES OPEN on Fri 27 April workshop

Courses in April 
Mon 23  : Making a Start in E-Commerce with Shop at ssistant
Tue 24  : Meeting Business Needs with the Shop at ssistant Classic system
Wed 25 : Building Better Shopping Pages with Shop at ssistant Classic


Booking for these Shop at ssistant Classic courses at 
http://www.shopassistant.net/training/  
Or call 01256 880770

Rodney Myers
Based in Oxford, England
Technical Director, Shop at ssistant eCommerce Solutions




More information about the Javascript mailing list