Search code examples
htmlformssend

html - how to send to email both - select tag value and input value?


<!DOCTYPE html>
<html>
<body>

<form action="" method="post" enctype="text/plain">
IP Address:<br>
<input type="text" name="" placeholder=""><br>
Port:<br>
<input type="text" name="" placeholder=""><br>
Game:<br>
<input type="text" name="" placeholder="" ><br>
Type:<br>
<input type="option" name="Type" size="50"><br><br>
<select name="cars">
    <option value="volvo">Volvo XC90</option>
    <option value="saab">Saab 95</option>
    <option value="mercedes">Mercedes SLK</option>
    <option value="audi">Audi TT</option>
  </select>

<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
</body>
</html>

I want to send this to mail when I write the right action="mailto:....." I can send only the input things, but not select tag selected option i tried any of this things separately it works but when i wanna do this with one button it doesn't works...


Solution

  • you can use in your HTML somthing like this :

    <script src="https://code.jquery.com/jquery-3.1.0.js"></script>
    
    <input type="email" name="email" placeholder="Email" id="Email"><br>
    <input type="text" name="titre" placeholder="Title" id="Title"><br>
    <textarea name="content" placeholder="Content" id="Content"></textarea><br>
    <button id="send">send</button>
    

    Now using jquery add this :

    $("#send").click(function(){
       var email=$('#Email').val();
       var title=$('#Title').val();
       var content=$('#Content').val();
       document.location.href = "mailto:"+email+"?subject="+title+"&body="+content;
    });
    

    for the options tag in your select you have to know that you can only send the selected value from options inside the select tag

    hope this will help you.