1

I have a question and I think I know the answer.

Have some html code where im using the action="mailto: function.

My question is can I assign the Subject to the generated email from the selection in the code below? E.g. Subject: Urgent; when urgent is selected.

<head>
<title></title>
</head>
<body>
<form enctype="text/plain" method="post" id="orderform" action="mailto:randomeemail@gmail.com?subject" >
<table border="1" align="left" style="width: 100%">
    <tbody>`enter code here`
      <tr>
       <td style="text-align: justify;"><label for="element_10" class="Deliverys">What
           Type of Delivery is required?</label></td>
        <td style="text-align: justify;">
          <select name="Urgency Required">
            <option value="Standard">Standard Delivery</option>
            <option value="Fast">Fast</option>
            <option value="Urgent">Urgent</option>
            <option value="Required in 4 hours">Required in 4 hours</option>
            <option value="Required in 2 hours">Required in 2 hours</option>
            <option value="Pick-up">Pick-up</option>
          </select>
        </td>
      </tr>
<input type="submit" value="Submit" name="Submit" />
</form> 
</body> 
</html>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

If you don't mind using Javascript, you can do the following:

<script>
function myFunction(){
  window.location.href = 'mailto:randomeemail@gmail.com?subject=' + document.querySelector('select[name="Urgency Required"]').value
  return false
}
</script>

<form enctype="text/plain" method="post" id="orderform" onsubmit="return myFunction();" >
<table border="1" align="left" style="width: 100%">
    <tbody>`enter code here`
      <tr>
       <td style="text-align: justify;"><label for="element_10" class="Deliverys">What
           Type of Delivery is required?</label></td>
        <td style="text-align: justify;">
          <select name="Urgency Required">
            <option value="Standard">Standard Delivery</option>
            <option value="Fast">Fast</option>
            <option value="Urgent">Urgent</option>
            <option value="Required in 4 hours">Required in 4 hours</option>
            <option value="Required in 2 hours">Required in 2 hours</option>
            <option value="Pick-up">Pick-up</option>
          </select>
        </td>
      </tr>
        <input type="submit" value="Submit" name="Submit"></input>
    </tbody>
  </table>
</form> 

Bascially, when the form submits, it'll dynamically generate the mailto link, and open it. It then returns false, which stops the form from actually submitting (i.e. redirecting to the action).

Nick Grealy
  • 24,216
  • 9
  • 104
  • 119