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>


 
What's the error message?


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
code said:
unless(setaddress() >1)

The 'a' in 'setaddress' needs to be capitalized. set[!]A[/!]ddress.

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Ha! I just glossed right over that!

Wishful thinking, I guess! An unless(...) feature would be interesting, I think!

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
I guess it wouldn't be that hard to code!

"Unless boolTest is true, do the blocked-code" == "If the boolTest is true, DON'T do the blocked-code" == "If the boolTest is NOT true, DO the blocked-code"

...translates easily into:

Code:
function unless(boolTest)
{
 return !boolTest;
}

Whatever.

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Dan, you remind me of the whale who wore diapers to the party.

He was a party pooper!

Let me have my fun!

:-D


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Thanks gentlemen...unless is the same as elseif...

Basically when I run the program on the explorer...It gives me "error on page" at the bottom.Anything I can do to modify where the code will allow me select multiple users and send out an email.Just like when I select one and it allows me to send the email to the user..

 
unless is the same as elseif

But elseif is not a JavaScript command either! "else if" (2 distinct words) maybe, but not as one.

If you are still using the "unless" code and are getting errors, maybe you should try removing it?

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
ok....I took it out, but I still received an error on the page...Do you see any coding syntax errors that I don't see.I'm a little dumbfounded on this one....Any suggestion anything I can do differently..
 
Do you get that little yellow exclamation point icon on the bottom left corner of your screen when you get this error? Click on it. Read and REPORT the EXACT text of the error. There is a clue.

Also, you might consider posting your latest version of the code. Please put it between the [ignore]
Code:
...
[/ignore] tags to make it more readable.

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
And when do you get the error? When the page loads? When you select an item from your SELECT? When you UNselect an item?


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
What error do you recieve? Have you tried looking at the page in Firefox and checking the JavaScript console?

You need to be a bit more informative... and with errors, usually the error message (in Fx, at least) is enough to help you to help yourself.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks everyone's you've been helpfull...And Yes, I clicked on the exclamation point and it states line 104, char 1, error object expectecd, code 0....


And the error comes when I select an item from the menu..
I've ran though the code I can't determine what's missing..Here is the code again and changed the unless to else if...






<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;

}
unless(myindex >1)
{
address=document.email.address.options[myindex].value;
document.email.display.value=address;
address1=document.email.address1.options[myindex].value;
document.email.display.value=address1;
address2=document.email.address2.options[myindex].value;
document.email.display.value=address2;
}
// 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;


}
else if(setAddress() >1)
{
alert("\nYou have selected more than one address..Hit OK to continue.")
window.location="mailto:"+address+;+address1+;+address2+"?subject=Multiple Email Example"+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()">
<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>

 
What is line 104?

You do not seem to have replaced "unless" at all.

If you merely replace "unless" with "else if", the condition-block will never execute because if the condition is true, it would have been true in the above if-statement.

The "object exected" error usually indicates that you appear to be calling a function, but you have not defined the function anywhere and it is not a standard JavaScript built-in function. Something like unless(...) perhaps?

Listen, we REALLY want to help you. You're not making it any easier. Provide all the details, incorporate our suggestions before posting code. Post code in between [ignore]
Code:
[/ignore] tags. Like this: [ignore]
Code:
This is my code.
[/ignore] It will come out looking like:
Code:
This is my code.
It really makes it easier to read.

Etc.

Thanks.

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
IE's JavaScript error messages are notoriously unhelpful. As I've suggested, use Firefox and look in the JavaScript console - you'll probably see the error and find you can fix it no problem, as it's virtually guaranteed to be more meaningful.

As Dave says, you've still got the "unless" statement in, and you're still not posting your code in [ignore]
Code:
[/ignore] tags.

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Also apart from "unless".
[1] Why is that?
[tt]<head>
<body>
<!-- etc -->
</head>
<!-- etc -->
</body>
[/tt]
[2] What is this syntax?
>[tt] window.location="mailto:"+address+;+address1+;+address2+"?subject=Multiple Email Example"+message;[/tt]
[tt] window.location="mailto:"+address+[red]","[/red]+address1+[red]","[/red]+address2+"?subject=Multiple Email Example"+message;
[/tt]
[3] You never make proper use of Multiple client-side to retrieve multiple address, so why multiple?
 
posted the wrong code.I understand, I'll try firefox...Not quite sure about this syntax I have....I'm attempting to apply mulitple address to the email...Is this the correct syntax for window.location(tsuji)?
[2] What is this syntax?
> window.location="mailto:"+address+;+address1+;+address2+"?subject=Multiple Email Example"+message;
window.location="mailto:"+address+","+address1+","+address2+
"?subject=Multiple Email Example"+message;


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;
    
      }
    else if(myindex >1)
    {
       address=document.email.address.options[myindex].value;
       document.email.display.value=address;
       address1=document.email.address1.options[myindex].value;
       document.email.display.value=address1;
       address2=document.email.address2.options[myindex].value;
        document.email.display.value=address2;
        }
   // 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;
    

    }
   else if(setAddress() >1)
      {
    alert("\nYou have selected more than one address..Hit OK to continue.")
    window.location="mailto:"+address+;+address1+;+address2+"?subject=Multiple 
Email Example"+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()">
   <SELECT NAME="address" MULTIPLE SIZE=4 onChange="setAddress()">
   <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>
Multiple Email
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top