Click to See Complete Forum and Search --> : HTML help
orangecuse
01-12-2005, 09:40 PM
Hello, I would like to introduce myself by asking a question. I am trying to figure out how to copy text from a textbox using the submit button.
For example, say I have this...
<form>
<input type="text" name="textbox">
<br>
<input type="submit" value="submit">
</form>
Say the user enters data into the text box. How do I get the submit button to copy what the user enters in the text box. Thanks in advance.
PeOfEo
01-12-2005, 09:52 PM
what do you mean? Do you want what the user has typed to be copied (ctrl-c?)?
orangecuse
01-12-2005, 10:35 PM
Originally posted by PeOfEo
what do you mean? Do you want what the user has typed to be copied (ctrl-c?)?
correct, i just want the data entered by the user to be copied like ctrl-c
This copy only works in IE, but if you want it to be compatible with other browsers, it will just select the text - saves the user a step ;) ...
function SelectCode() {
document.abc.textbox.select();
document.abc.textbox.focus();
}
function CopyCode() {
SelectCode();
textRange = document.abc.textbox.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");
alert("This code has been copied to your clipboard.\nOpen your HTML page and paste it in.");
}
NOTE: give your form a name, such as in this code I called the form "abc". To give your form a name change: <form> to <form name="abc">
You will call the code:
<script language="JavaScript" type="text/javascript">
<!--
if ((navigator.appName=="Microsoft Internet Explorer")&&(parseInt(navigator.appVersion)>=4)) {
document.write("<INPUT type='button' value='Copy To ClipBoard' onClick='CopyCode()'>");
} else {
document.write("<INPUT type='button' value='HighLight Code' onClick='SelectCode()'>");
}
// -->
</script>
orangecuse
01-14-2005, 06:25 PM
I see, you answered my question and more! Thank you.:cool: