What is wrong with this code? Form Submission!

Discussion in 'Web Design and Development' started by ktbubster, May 24, 2009.

  1. ktbubster macrumors 6502a

    ktbubster

    Joined:
    Jan 20, 2007
    Location:
    US
    #1
    Hey all,

    I'm having an issue. I'm trying to code a simple form so that people can enter in their email, phone, etc and when they click submit it will be sent to my email address. I got some code offline that I thought would work, but while the form and everything works, the submit button doesn't work so I don't get the information sent to me. Could someone help me and let me know what's wrong?

    I substituted emailemail@hotmail.com for where my address i thought was supposed to go. Am i missing another place or did I just make a typing error?
    Code:
    <TITLE></TITLE> 
    
    <script language="javascript"> 
       function SendEmail(frm){ 
         var emailAddress="emailemail@hotmail.com" 
        var message = "name:" + frm.txtName.value + "\n"; 
        message = message +"phone:" +  frm.txtold phone.value; 
        message = message +"email:" + frm.txtemail.value; 
        document.location.href = "mailto:"+emailemail@hotmail.com+"?subject=Test Mail&body="+escape(message); 
       } 
    </script> 
    
    <BODY> 
    <form name="frmSendEmail" > 
    <TABLE> 
    <TR> 
    <TD vAlign=center align=right width="35%"> 
    name: 
    </TD> 
    <TD width="65%"><input type=text name=txtold value=""></TD></TR> 
    <TR> 
    <TD vAlign=center align=right width="35%"> 
    phone: 
    </TD> 
    <TD width="65%"><input type=text name=txtpass value=""></TD></TR> 
    <TR> 
    <TD vAlign=center align=right width="35%"> 
    email: 
    </TD> 
    <TD width="65%"><input type=text name=txtpass value=""></TD></TR> 
    <TR><TD vAlign=center align=center width="100%" colspan=3> 
    <INPUT TYPE="button" name="submit" Value="submit" onclick="SendEmail(this.form)"> 
    </TD></TR> 
    </TABLE> 
    </form> 
    </BODY>
     
  2. Cabbit macrumors 68020

    Cabbit

    Joined:
    Jan 30, 2006
    Location:
    Scotland
    #2
    I don't know enough about javascript yet to aid in how the script works but form my understanding of dealing with forms your form only have a name and no method or action. Usually a form would start like this:

    HTML:
    <form action="processme.php" method="post">
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    Try this for the script block,
    PHP:
    <script type="text/javascript">
       function 
    SendEmail(frm) {
         var 
    emailAddress "emailemail@hotmail.com";
         var 
    message "name: " frm.txtName.value "\n";
         
    message +=  "phone: " +  frm.txtold phone.value "\n";
         
    message += "email: " frm.txtemail.value "\n";
         
    document.location "mailto:" emailAddress
           
    "?subject=Test Mail&body=" escape(message);
       }
    </script>
    Then some mods to your HTML,
    HTML:
    <form name="frmSendEmail" onsubmit="SendEmail(this)">
    ...
    <INPUT TYPE="submit" name="submit" Value="submit"> 
    
     

Share This Page