简体   繁体   中英

Getting Submit Button to Pick Up Text in Textarea

I have a textarea that shows a random joke. I want the joke to post to Twitter using this link with the submit button: https://twitter.com/intent/tweet?text= but I cannot for the life of me figure out how to get the text that's been generated in the textarea to be picked up in the link. I know there's an easy way to make this happen, but nothing I've tried has worked. Any help would be greatly appreciated:!! Here's the code I've got:

<form name="quoteForm">
  <textarea wrap="virtual" name="quoteHere" rows="6" cols="40">Your joke is loading... unless your JavaScript is disabled
  </textarea><br>  <input type=button value="Previous" onClick="prevQuote();">
  <input type=button value="Next" onClick="nextQuote();">
  <input type=button value="Random" onclick="randQuote();"><br>
    <p>
    <input type="submit" value="Tweet This Joke"></p>
</form>

The name attribute of textarea was changed from quoteHere to text .

<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
</head>
<body>
<form name="quoteForm" action="https://twitter.com/intent/tweet" onsubmit="submit();">
  <textarea wrap="virtual" name="text" rows="6" cols="40">Your joke is loading... unless your JavaScript is disabled
  </textarea><br>  <input type=button value="Previous" onClick="prevQuote();">
  <input type=button value="Next" onClick="nextQuote();">
  <input type=button value="Random" onclick="randQuote();"><br>
  <p><input type="submit" value="Tweet This Joke"></p>
</form>
</body>
</html>

If you want to put the data in the query string then you need to make a GET request (which you are already doing), not a POST request (which you say you want to do).

If you want to send the data to https://twitter.com/intent/tweet then you need to put that URL in the action attribute of the <form> element. Since you have no action it will submit to the URL of your current page instead.

If you want the data to be associated with the query string parameter text then you need to name the textarea text and not, as you have, quoteHere .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM