开发者

How to pass the dropdown and text value to email subject line using Javascript

Need your urgent help

I have one HTML page with 2 text box, 1 dropdown and 1 button, on button click I want to open the email(as currently I am doing with javascript) with subject line as whatever is selected in the drop down and whatever is written in text box.

<body>
<form id='sampleform' method='post' action='' > 
   Emp Number: <input type='text' name='empnum' />  

   </p>  

   <p>  
       Unit Name: <input type='text' name='unit' />   
   </p>  
   <p>  
       Type of subscription you want:  
   <p>  
       <select name="type">  
           <option value="standard">Standard - Free</option>  
           <option value="prof">Professional - Paid</option>  
       </select>   
   </p>  
   </p>  
   <p>          
      <input type='submit' name='Submit' value='Submit开发者_运维技巧' onClick="parent.location='mailto:er.saurav1@gmail.com?subject=Thanks for writing &body=Hi,%0A%0CThanks for writing. We will get back to you soon. %0A%0C%0D%0AThanks and Regards,%0A%0CSaurav Kumar%0A%0C%0A%0CFor further assistance call 81111'">
   </p> 
</form> 

</body>

I want when my email will open the subject line output should be:

Emp Num | Unit Name | Selected value from the drop down


I re-edited the post from Srikanth Rayabhagi. Now it should work

<script type='text/javascript'>
    function sendMail(){
        var form = document.forms.sampleform;
        var empnum = form.empnum.value;
        var uname = form.unit.value;
        var ddvalue = form.type.options[form.type.selectedIndex].value;
        var subj = empnum + '|' + uname + '|' + ddvalue;
        parent.location='mailto:abc@gmail.com?subject=' + encodeURIComponent(subj) +'&body=Thanks for writing. We will get back to you soon';
    }
</script>

Just call sendMail() within any Button onClick event.

hth


Run this in your onclick:

var form = document.forms.sampleform;
var subject = form.empnum.value + ' | ' + form.unit.value + ' | ' + form.type.value;
parent.location = 'mailto:er.saurav1@gmail.com?subject=' + encodeURIComponent(subject) + '&body=...';


<script type="text/javascript" charset="utf-8">
    function click_handler(){

            var x = document.forms.sampleform;
            var enum = x.empnum.value;
            var uname = x.unit.value;
            var ddvalue = x.type.options[x.type.selectedIndex].value;
            var subj = enum +'|'+uname+'|'+ddvalue;
            parent.location='mailto:abc@gmail.com?subject=' + encodeURIComponent(subj) +'&body=Thanks for writing. We will get back to you soon';

    }
</script>
<body>
<form id='sampleform' name='sampleform'> 
   Emp Number: <input type='text' name='empnum' />  

   </p>  

   <p>  

   Unit Name: <input type='text' name='unit' />  

   </p>  

    <p>  

   Type of subscription you want:  

    <p>  

    <select name="type">  

      <option value="standard">Standard - Free</option>  

      <option value="prof">Professional - Paid</option>  

    </select>  

    </p>  

  </p>  
  <p>  

<input type='button' name='Submit' value='Submit' onClick="javascript:click_handler()">
</p> 
</form> 
</body>
 </html>

Will be fine.. Though didn't check by running it.. Call the click_handler_me() on clicking the button.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜