0

so I'm trying to pass the value of "x" here which will generate the random value.

<script>

  var result = Math.random().toString(36).substring(2,5);
  window.onload = function() {
     document.getElementById("x").innerHTML=result;
  } 

</script>

I want to pass the value to my html code, in the mailto subject. so when people click the link, it will automatically open the default mail and send the email to info@legianbeachbali.com with the subject "Special Promotion + (random code)"

<p style="color: #5b5b5b; text-align: left; id: x;">
<a title="Book Now" href="mailto:info@legianbeachbali.com?subject=Special%20Promotion%20"+x>Book Directly with Us</a></p>

I tried to call the value on id and put "x" in the subject but as I expected, it doesn't work. could you guys please help me? I need to know how to show the value in the subject email.

Thanks in advance.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • Did you look at this: http://stackoverflow.com/questions/4782068/can-i-set-subject-content-of-email-with-using-mailto – Sanj Nov 10 '16 at 03:56

1 Answers1

0

First remove + x from your HTML i.e, href attribute of your a tag. Then add id to you a tag mailTo in this case (as shown below).

$(function() {
 
 var result = Math.random().toString(36).substring(2,5);
 var href =  $("#mailTo").attr('href')  
 var  newHref = href + result
 $("#mailTo").attr("href", newHref)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a title="Book Now" id='mailTo' href="mailto:info@legianbeachbali.com?subject=Special%20Promotion%20">Book Directly with Us</a></p>
Gaurav joshi
  • 1,743
  • 1
  • 14
  • 28