0
function copyToClipboard (text) {
  window.prompt ("Copy to clipboard: Ctrl+C, Enter", text);
}

The form looks like this:

<table>
<form action="myform.php" method="post" onsubmit="return copytoClipboard()"           name="incidentCreator">
<th colspan="2">Incident Creator</th>
<tr>
<td>Email: <input type="text" name="email" value="" /></td>
<td rowspan="9"> 

</td>
</tr>
<tr>
<td>Name: <input name="name" value=""></td>
</tr>
<tr>

<td>Phone: <input type="text" name="phone" value="" /></td>
</tr>


function copyToClipboard (text) {
window.prompt ("Copy to clipboard: Ctrl+C, Enter", text);
}

Somebody posted this as a solution to copy to the clipboard, but it doesn't show how to use it. I am new to Javascript and am trying to output text from an HTML form into a format as

Can anyone show me an example of how I would take the above form data and present it ready to be copied with this Javascript function?

Paxwell
  • 748
  • 10
  • 18
  • prompt does not have line feeds. – epascarello Apr 11 '12 at 21:26
  • If anyone can just show how to use the javascript function to post data to the window ready to copy I can figure the rest out. :) thanks. – Paxwell Apr 11 '12 at 21:27
  • What values will be copied when you press Ctrl+C? Just the active input box or all of them? – Brig Apr 11 '12 at 21:41
  • All of them. But if anyone can just show how to use the function above to do one, it would help. No body has really answered my question. – Paxwell Apr 13 '12 at 15:51

2 Answers2

0

If you want users to get the form in the format you want you will have to render the text yourself, based on the HTML form . use jQuery to get all the fields you need , then generate the final text and let the user copy the formatted text you rendered themself. You can use

 tags to have preformated text in your html ( it will render line breaks , and tabs ,etc ...). You could use a pop up to display the final text for instance.

Anyway there is no function in javascript that automatically does what you want to do.

mpm
  • 20,148
  • 7
  • 50
  • 55
0

Convert your form to JSON string. First create JavaScript object from your fields (http://stackoverflow.com/questions/1184624/convert-form-data-to-js-object-with-jquery), then convert it to string using http://api.jquery.com/jQuery.parseJSON.

Piotr Kochański
  • 21,862
  • 7
  • 70
  • 77