#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    30
    Rep Power
    12

    Unhappy javascript form to mail problem


    Hi -- I am just a beginner in programming and javascript, and would be really, really grateful if anyone could help me with this. I'm trying to write a web version of a "while you were out" phone message pad -- basically a form with checkboxes and textboxes which you can fill in and e-mail to one or more people. But I'm trying to create a second form which sends the actual e-mail -- the benefit of this is that I should be able to format the message so that it reads like a regular piece of mail rather than having it be sent in the standard name=value pairs of a normal 'mailto:' form. But it's not working! Please, can anyone help? I'm going mad!!!
    Thank you.

    Here's the code:


    <html>
    <body>
    <!-- adapted from http://home.earthlink.net/~jeffreyfarkas/mailform.html and http://members.ozemail.com.au/~dcrombie/mailform2.html. -->

    <form name="mailer" method="post">
    <input type="hidden" name="mtp" value=" ">
    <table border="1" cellspacing="0" cellpadding="0"><tr><td>
    <table border="0" cellspacing="2" cellpadding="5">

    <tr>
    <td colspan="4">
    <h2>While You Were Out</h2>
    </td>
    </tr>
    <tr>
    <td align="right">
    <h3>Message For:</h3>
    (Multiple choices allowed)
    </td>
    <td colspan="3">
    <table border="0" cellspacing="2" cellpadding="5">
    <tr>
    <td><input type="checkbox" name="N1" value="one@address.com"/>One</td>
    <td><input type="checkbox" name="N2" value="two@address.com"/>two</td>
    <!--<td valign="top" rowspan="2">
    Or enter e-mail:<br /><br /><input type="text" name="to" size="30"/> -->
    </td>
    </tr>
    <tr>
    <td><input type="checkbox" name="N3"value="three@address.com"/>three</td>
    <td><input type="checkbox" name="N4" value="four@address.com"/>four</td>
    </tr>
    </table>
    </td>
    </tr>

    <tr>
    <td align="right">Taken By:</td>
    <td colspan="3">
    <table border="0" cellspacing="2" cellpadding="5">
    <tr>
    <td width="75%">
    <select name="takenby" />
    <option value="one"> one</option>
    <option value="two"> two</option>
    <option value="three"> three</option>
    <option value="four"> four</option>
    </select>
    </td>
    <!--<td>
    Or enter e-mail:<br /><input type="text" name="taker" size="30"/>
    </td>-->
    </tr>
    </table>
    </td>
    </tr>

    <tr>
    <td align="right">Date:</td>
    <td><input type="text" name="date" value="01/01/03" maxlength="8" /></td>
    <td align="right">Time:</td>
    <td><input type="text" name="time" value="09:00" maxlength="5" /></td>
    </tr>

    <tr>
    <td align="right">
    <select name="Caller-Title">
    <option>Mr.</option>
    <option>Mrs.</option>
    <option>Ms.</option>
    <option>Dr.</option>
    </select>
    </td>
    <td colspan="3"><input type="text" name="Caller-Name" size="30" /></td>
    </tr>

    <tr>
    <td align="right">Company:</td>
    <td colspan="3"><input type="text" name="Company" size="30" /></td>
    </tr>
    <tr>
    <td align="right">Phone:</td>
    <td colspan="3"><input type="text" name="Phone" size="30" /></td>
    </tr>

    <tr>
    <td />
    <td colspan="3">
    <table border="0" cellspacing="1" cellpadding="0">
    <tr>
    <td><input type="checkbox" name="notes" value="Returned Call" />Returned Call</input></td>
    <td><input type="checkbox" name="notes" value="Please Call" />Please Call</input></td>
    </tr>
    <tr>
    <td><input type="checkbox" name="notes" value="Will Call Again" />Will Call Again</input></td>
    <td><input type="checkbox" name="notes" value="Urgent" />Urgent</input></td>
    </tr>
    </table>
    </td>
    </tr>

    <tr>
    <td align="right">Subject:</td>
    <td colspan="3"><input type="text" name="subject" size="30" /></td>
    </tr>



    <tr>
    <td />
    <td colspan="3">
    <table border="0" cellspacing="2" cellpadding="2">
    <tr>
    <td colspan="4">
    Message:<br />
    <textarea name="message" cols="40" rows="10" wrap="virtual" OnChange="msg(this.form)"></textarea>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>

    <FORM name="mailForm" action="mailto:" method="post" enctype="text/plain" onSubmit="return mailIt();">
    <!-- The contents of this field are filled out when the submit button is pressed -->
    <INPUT type="hidden" name="mailBody" value="">

    <tr>
    <td colspan="4" align="right">
    <input type="submit" value="Send Message" onClick="return true";>
    <input type="reset" value="Reset Form" onclick="Rset()" />
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>

    <script language="JavaScript">
    var message=mailer.message.value;
    N1val=0;
    N2val=0;
    N3val=0;
    N4val=0;
    var mailer = document.mailer; //visible form
    var mailForm = document mailForm; //hidden form

    function mailIt(){

    // redefine the mailForm action property

    mailForm.action="mailto:" + mailtoandsubject;

    //make up mailForm message
    var mFmessage += 'You got a phone call from: ' + mailer.Caller-Title.value + ' ' + mailer.Caller-Name.value + 'of: ' + mailer.Company.value + 'on: ' + mailer.date.value + 'at: ' + mailer.time.value + '.' + '\r\n\r\n' + ' Phone number: ' + mailer.Phone.value + '.' + '\r\n\r\n'+ ' Notes: '+ mailer.notes.value+'.';

    //transfer all information from mailer to mailForm for sending
    mailForm.mailBody.value = mFmessage + '\r\n\r\n' + message;

    }

    function msg(){


    if (mailer.N1.checked==true && N1val==0) {
    mailer.mtp.value = mailer.mtp.value + mailer.N1.value + ";";
    N1val=1;
    }

    if (mailer.N2.checked==true && N2val==0) {
    mailer.mtp.value = mailer.mtp.value + mailer.N2.value + ";";
    N2val=1;
    }

    if (mailer.N3.checked==true && N3val==0) {
    mailer.mtp.value = mailer.mtp.value + mailer.N3.value + ";";
    N3val=1;
    }

    if (mailer.N4.checked==true && N4val==0) {
    mailer.mtp.value = mailer.mtp.value + mailer.N4.value + ";";
    N4val=1;
    }

    mailtoandsubject= (document.mailer.mtp.value + ' ?subject=' + document.mailer.subject.value);
    }

    function Rset(){
    N1val=0;
    N2val=0;
    N3val=0;
    N4val=0;
    }

    </script>

    </body>
    </html>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    30
    Rep Power
    12

    addendum


    I realise I should have pointed out specifically what is going wrong with my form to mail javascript -- an e-mail is being created, but without any content, the message just says "mailBody=", and the subject says "Form posted from Internet Explorer", and there is nothing in the send to or sender sections.
    Please help!
    -- Munna

IMN logo majestic logo threadwatch logo seochat tools logo