423,688 Members | 1,889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,688 IT Pros & Developers. It's quick & easy.

Insert code only link into textarea

P: 21
This should be very simple.
It is NOT a live link!
I have no idea how to do this, so need some help please.

Expand|Select|Wrap|Line Numbers
  1. <form>
  2. <input type="button" id="link" value="Link"><br>
  3. <textarea name="message" style="width:40%; height:100px;">
  4. <a href="http://domain.com">Name</a>
  5. </textarea><br>
  6. <input type="submit" value="Save">
  7. </form>
  8.  
The object is to:
1 Click the Link button.
2 Enter URL into 1st prompt
3 Enter Name into 2nd prompt
4 The HTML will show in the textarea (like above)
5 Save does all the rest elsewhere.

I reckon this will probably not be more than 1k of JavaScript.

Hope someone can help - thanks in advance.
2 Weeks Ago #1
Share this Question
Share on Google+
5 Replies


Expert 100+
P: 931
In your scenario, I think point 2 and 3 should go before point 1. Its' much easier to first input the data you need, and by clicking on the link start to do something with that data.

About point 4: I think it's not possible to show HTML of an external site in a textarea.

You should use IFRAME for that purpose.
2 Weeks Ago #2

P: 21
Thanks

HTML in a textarea is standard for editors. The code gets parsed when processed.
6 Days Ago #3

Expert 100+
P: 931
OK, I was bored, so I googled for the answer I did not know, and hers is the output:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <script>
  5.  
  6.         // https://stackoverflow.com/questions/10642289/return-html-content-as-a-string-given-url-javascript-function
  7.         function httpGet(theUrl) {
  8.             if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  9.                 xmlhttp = new XMLHttpRequest();
  10.             }
  11.             else {// code for IE6, IE5
  12.                 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  13.             }
  14.             xmlhttp.onreadystatechange = function () {
  15.                 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  16.                     document.getElementById('returnText').value = xmlhttp.responseText;
  17.                     //returnText.value = "TESTTEXT";
  18.                     //return "TESTTEXT";
  19.                     //return xmlhttp.responseText;
  20.                 }
  21.             }
  22.             xmlhttp.open("GET", theUrl, false);
  23.             xmlhttp.send();
  24.         }
  25.  
  26.  
  27.         function dostuff() {
  28.             var link = document.getElementById('textlink');
  29.             alert('dostuff:' + link.value);
  30.             httpGet(link.value);
  31.  
  32.         }
  33.  
  34.     </script>
  35. </head>
  36. <body>
  37.     <input type="button" id="link" value="Link" onclick="dostuff()"><br>
  38. <textarea id='textlink'>http://domain.com</textarea>
  39.     <form onsubmit="dostuff()">
  40.         <input type="button" id="link" value="Link" onsubmit="dostuff()"><br>
  41. <textarea name="message" id="returnText" style="width:40%; height:100px;">
  42. <a href="http://domain.com">Name</a>
  43. <h1>TEST-H1</h1>
  44. </textarea><br>
  45.         <input type="submit" value="Save">
  46.     </form>
  47.     <p>You might get an error described on this page: https://techsupport.osisoft.com/Documentation/PI-Web-API/help/topics/cross-origin-resource-sharing.html</p>
  48. </body>
  49. </html>
6 Days Ago #4

P: 1
Can you do it vice versa? Maybe it will help?
5 Days Ago #5

Expert 100+
P: 931
"vice versa"?, you mean putting the (html-)code back on the server?

That will be pretty useless. A properly configured server will not allow that (to be done from a remote location).

Also a lot of servers use logic to create HTML-pages, like PHP, NodeJS, .ASP . If that's the case, than it will be even more useless to put code back to the server.
4 Days Ago #6

Post your reply

Sign in to post your reply or Sign up for a free account.