Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mail Menu Form (javascript problem)

Status
Not open for further replies.

menace212

Programmer
Joined
Jul 11, 2003
Messages
144
Location
US
I have a script that allows the user to send an email from a form menu..I have it were it sends one email, but I need to script to allow the user to send as many emails as the menu allows. The problem is I think I have the setup correct, but I keeping getting a error on my code..Can someone see the error I'm making with the code or have a better way of writing the code.







<HTML>
<HEAD>
<BODY>

<SCRIPT>
<!-- Activate Cloaking Device

// Identify browser - not all browsers handle email the same.
var browser=navigator.appName + " " + navigator.appVersion;

// Add a message to the body for Netscape 4.0
var message="";
if(browser.substring(0, 12)=="Netscape 4.0")
message="&body=This is for demonstration only... \n\n\n DO NOT SEND THIS MESSAGE!";
// Used to display and load email address
var address="";
var address1="";
var address2="";

// Called by onChange in select tag


function setAddress()
{

// Sets myindex to index of selected menu item
var myindex=document.email.address.selectedIndex;

// If an item other than 0 has been chosen
if (myindex >= 1)
{
address=document.email.address.options[myindex].value;
document.email.display.value=address;

return true;

}

// If no item has been chosen
else
{
document.email.display.value="Choose an address from the menu...";
return false;
}

}

// Called by View Mail Window button
function doMail()
{
// Checks if an address has been selected
if(setAddress()){
window.location="mailto:"+address+"?subject=Multiple Email Example"+message;


}
unless(setaddress() >1)
{
alert("\nYou have selected more than one address..Hit OK to continue.")
window.location="mailto:"+address+;+address1+;+address2+"?subject=Multiple Email"+message;
}
else
{
alert("\nYou must select an address from the menu first.");
return false;
}
}

// Called by Reset The Form button - impelmented for Netscape 2
function resetForm()
{
document.email.address.options[0].selected = true;
}



// Deactivate Cloaking -->
</SCRIPT>
</HEAD>


<BR>



<BR><BR>

<CENTER>
<FORM NAME="email">

<SELECT NAME="address" MULTIPLE SIZE=4 onChange="setAddress()">
<OPTION SELECTED VALUE="">Griffin Address Book
<OPTION value="glewis@anywhere.com">Greg lewis</option>
<OPTION VALUE="dhill@anywhere.com"> Doug Hill</option>
<OPTION VALUE="smike@anywhere.com">Sam Mike</option>
<OPTION "mbrown@where-ever.com">Mack brown</option>
<OPTION "jharris@where-ever.com">Joey Harris</option>
</SELECT>

<BR><BR>

<INPUT TYPE="text" NAME="display" SIZE="40" VALUE="Choose an address from the menu...">
<input type="submit" name="submit" value="Submit" onClick="doMail()">

<BR><BR><BR>


<BR><BR>

<TABLE BORDER="3" WIDTH="100">
<TR>
<TD align="center">
<INPUT TYPE="reset" VALUE="Reset The Form" onClick="resetForm()">
</TD>
</TABLE>
</FORM>
</CENTER>

<BR>

<HR WIDTH=200 ALIGN=center SIZE=2>
<CENTER><ADDRESS><STRONG>


 
These are the errors I got using firefox...Not quite sure about setaddress and domail not defined...I'm pretty sure it's defined...Because I can do one address, but attempting to modify it to do multiple address is my problem....


Code:
Error: Warning: unrecognized command line flag -installer

Source File: file:///C:/Program%20Files/Mozilla%20Firefox/components/
nsBrowserContentHandler.js
Line: 511

Code:
Error: syntax error
Source File: file:///C:/Documents%20and%20Settings/adavis/Desktop/
temp.html
Line: 69, Column: 35
Source Code:
	window.location="mailto:"+address+;+address1+;+address2+"?subject=
Multiple Email Example"+message;


Code:
Error: setAddress is not defined
Source File: file:///C:/Documents%20and%20Settings/adavis/Desktop/
temp.html
Line: 1

Code:
Error: doMail is not defined
Source File: file:///C:/Documents%20and%20Settings/adavis/Desktop/
temp.html
Line: 1



Code:
Error: syntax error
Source File: file:///C:/Documents%20and%20Settings/adavis/Desktop/temp.html?
address=adavis%40hai.com&display=Choose+an+address+from+the+menu..
.&submit=Submit
Line: 69, Column: 35
Source Code:
	window.location="mailto:"+address+;+address1+;+address2+"?
subject=Multiple Email Example"+message;



Code:
Error: setAddress is not defined
Source File: file:///C:/Documents%20and%20Settings/adavis/Desktop/temp.html?
address=adavis%40hai.com&display=Choose+an+address+from+the+menu..
.&submit=Submit
Line: 1

Code:
Error: setAddress is not defined
Source File: file:///C:/Documents%20and%20Settings/adavis/Desktop/temp.html?
address=adavis%40hai.com&display=Choose+an+address+from+the+menu..
.&submit=Submit
Line: 1

Code:
Error: setAddress is not defined
Source File: file:///C:/Documents%20and%20Settings/adavis/Desktop/temp.html?
address=adavis%40hai.com&display=Choose+an+address+from+the+menu..
.&submit=Submit
Line: 1

Code:
Error: doMail is not defined
Source File: file:///C:/Documents%20and%20Settings/adavis/Desktop/temp.html?
address=adavis%40hai.com&display=Choose+an+address+from+the+menu..
.&submit=Submit
Line: 1

Code:
Error: syntax error
Source File: file:///C:/Documents%20and%20Settings/adavis/Desktop/temp.html?
address=adavis%40hai.com&address=cgeisler%40hai.com&address=
dskala%40hai.com&display=Choose+an+address+from+the+menu..
.&submit=Submit
Line: 69, Column: 35
Source Code:
	window.location="mailto:"+address+;+address1+;+address2+
"?subject=
Multiple Email Example"+message;


Code:
Error: setAddress is not defined
Source File: file:///C:/Documents%20and%20Settings/adavis/Desktop/temp.html?
address=adavis%40hai.com&address=cgeisler%40hai.com&address=
dskala%40hai.com&display=Choose+an+address+from+the+menu...&submit=Submit
Line: 1
 
First error ("Line: 511"): would need to see the JavaScript file (nsBrowserContentHandler.js) to be sure.

Second error: syntax problem... although I'm not 100% sure of the correct syntax. I would try:

Code:
window.location="mailto:"+address+[!]"[/!];[!]"[/!]+address1+[!]"[/!];[!]"[/!]+address2+"?subject=Multiple Email Example"+message;

Third and fourth errors may be a result of your tag problems. You open the <BODY> tag before you close the <HEAD> tag. The <SCRIPT></SCRIPT> section should be entirely within the <HEAD></HEAD> section. THEN open your <BODY></BODY> section. NOTE: tsuji pointed this out to you already.

The "not defined" problem might not be that, however. It could be the semi-colons appearing throughout the "mailto" line. That should go away if you use the quotes like I recommend.

The other errors look like repeats of the first four. Fix those and then report back.

Dave






~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
corrected the issues as suggested above...Although I still get the syntax error for the window.location...
 
I suspect that one of your addresses is null in the mailto URL and you end up with double-semi-colons in it.

You need to work on your program's logic-flow. As I mentioned in a previous post, this is messed up:

Code:
if (myindex >= 1) 
      {
      address=document.email.address.options[myindex].value;  
       document.email.display.value=address; 
         
      return true;
    
      }
    else if(myindex >1)
    {

...since the else-if block will NEVER execute. I'm guessing you are not getting the behavior out of your JavaScript that you expect.

Use alert-messages liberally to track program flow. For example:

Code:
if (myindex >= 1) 
      {
[!]alert("myindex>=1");[/!]
      address=document.email.address.options[myindex].value;  
       document.email.display.value=address; 
         
      return true;
    
      }
    else if(myindex >1)
    {
[!]alert("myindex>1");[/!]

...etc. This will help you track the flow of execution.

Also, what's going on here?:

Code:
if(setAddress())
    {
      window.location="mailto:"+address+"?subject=Multiple Email Example"+message;
    

    }
   else if(setAddress() >1)
      {

setAddress() returns true or false (or nothing, in the case of the unexecutable else-if block). It does not return a number, so how can it be ">1"?

Also use alert messages to see the value of variables. Consider changing:
Code:
window.location="mailto:"+address+"?subject=Multiple Email Example"+message;
to
Code:
var x = "mailto:"+address+"?subject=Multiple Email Example"+message;
alert(x); //let's you see the value before program tries to use it.
window.location=x;

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
ok, I'll try it...I'll keep working on it...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top