0

I'm new to Javascript, and am currently writing a custom HTML page for my tumblr.

I understand that you can toggle a button to call a function in JS. I'd like to know how to retrieve a user's username when the button is clicked, within this function. I would like to email this information back to myself but can find no documentation on this anywhere :(

I understand the Tumblr has its own stock Ask form. However, I would like to customize my own. My HTML form is below:

<form action="sendUsername()" >
    <textarea rows="4" cols="50" id="message"></textarea>
    <input type="submit" value="Submit">
</form>

JavaScript

function sendUsername(emailAddress, message){
   //email username and message to emailAddress
}
Adam Azad
  • 11,171
  • 5
  • 29
  • 70
Oscar Chambers
  • 899
  • 9
  • 25
  • 1
    As pointed out, you need a server language to send email, which Tumblr doesn't support. You can use a third party service such as http://mailchimp.com/ – mikedidthis Jan 20 '16 at 16:03

1 Answers1

-1

For the getting the username, you need HTML:

<input type="text" name="username" id="username" />

and JS:

var username = document.getElementByID('username').value; 

to get the input value stored in a variable

However, I don't think you can send an email to yourself straight from Javascript without a third-party API. It can be done using PHP's mail() function though

http://php.net/manual/en/function.mail.php

If you don't want to use PHP at all, then have a look at this: How to send an email from JavaScript

Community
  • 1
  • 1
user5697101
  • 571
  • 4
  • 12
  • Is the variable "username" part of the tumblr API or something? – Oscar Chambers Jan 19 '16 at 22:05
  • @OscarChambers no it's whatever you want to call the input field, "username" is just for clarity – user5697101 Jan 19 '16 at 22:14
  • 1
    I don't think Tumblr will allow this function per se, there is no access to any kind of back end language. So you are forced to use client side solution, like javascript. However, I have found a service which allows custom feedback forms to be added to tumblr pages: http://www.jotform.com/ but whilst you gain some functionality you will lose some control. – lharby Jan 20 '16 at 08:55