7 Replies - 4689 Views - Last Post: 03 December 2009 - 08:30 AM

#1 newbie01.php  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 09

Cut-and-Paste from one TEXTAREA to another TEXTAREA in the same form ?

Posted 30 November 2009 - 06:12 AM

Hi,

This is probably fairly easy for the PHP gurus but not for me.

Does anyone have an example of a PHP script/form where I can have two TEXTAREA on a form,
and when I click on a cut/copy/paste button, it cut/copy/paste from one TEXTAREA to another.

I know how to echo the contents of the TEXTAREA but I prefer to echo the contents to a TEXTAREA
of the same form on the same page instead.

It is kinda like a FORM verification script but instead of loading the page using echoes, I want
to be able to display the result of the TEXTAREA into another TEXTAREA on the same page.

Any advise will be very much appreciated. Thanks in advance.

Below is basically how the FORM should look like but I don't know how to code the PHP stuff.

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang='en'>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" />
<title>Example Cut/Copy TEXTAREA</title>
</head>
<body><center><h1>Example Cut/Copy TEXTAREA</h1>
<form id="form1" name="form1" method="post" action="<?php echo $PHP_SELF;?>">
   <textarea name="coded" cols="60" rows="8" id="coded"></textarea>
<br />
   <input type="submit" name="Submit" value="Cut/Copy/Convert" />
</form>
<textarea rows=20 cols=60><?php 
return $coded
?>
</textarea><br/>
</body>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: Cut-and-Paste from one TEXTAREA to another TEXTAREA in the same form ?

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,546
  • Joined: 23-August 08

Re: Cut-and-Paste from one TEXTAREA to another TEXTAREA in the same form ?

Posted 30 November 2009 - 07:37 AM

This is the sort of thing which would be done in Javascript, rather than PHP. I'll move it to the Javascript forum.
Was This Post Helpful? 0
  • +
  • -

#3 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 129
  • View blog
  • Posts: 832
  • Joined: 25-October 08

Re: Cut-and-Paste from one TEXTAREA to another TEXTAREA in the same form ?

Posted 30 November 2009 - 09:51 AM

Name your two <textarea>s something like id="TArea1" and id="TArea2'

Then with a <button> tag saying "COPY/PASTE" use onclick="document.getElementById('TArea2").value=document.getElementById('TArea1").value;
Was This Post Helpful? 1
  • +
  • -

#4 newbie01.php  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 09

Re: Cut-and-Paste from one TEXTAREA to another TEXTAREA in the same form ?

Posted 30 November 2009 - 04:01 PM

View PostJackOfAllTrades, on 30 Nov, 2009 - 06:37 AM, said:

This is the sort of thing which would be done in Javascript, rather than PHP. I'll move it to the Javascript forum.


Hi,

Thanks for reviewing my post.

The link below may give you a better example of what am wanting to do.

http://www.tareeinte...pts/byterun.php

Basically, am wanting to decode and encode PHP scripts for starters and then add more buttons later on.

Can you confirm that the base64_decode/encode is also available on Javascript?


View PostJMRKER, on 30 Nov, 2009 - 08:51 AM, said:

Name your two <textarea>s something like id="TArea1" and id="TArea2'

Then with a <button> tag saying "COPY/PASTE" use onclick="document.getElementById('TArea2").value=document.getElementById('TArea1").value;


Hi,

Thanks for reviewing my post.

The link below may give you a better example of what am wanting to do.

http://www.tareeinte...pts/byterun.php

Basically, am wanting to decode and encode PHP scripts for starters and then add more buttons later on.

Can you confirm that the base64_decode/encode is also available on Javascript?
Was This Post Helpful? 0
  • +
  • -

#5 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 129
  • View blog
  • Posts: 832
  • Joined: 25-October 08

Re: Cut-and-Paste from one TEXTAREA to another TEXTAREA in the same form ?

Posted 30 November 2009 - 05:16 PM

For a JS prototype solution to your query, try this...
String.prototype.base64_encode=function(){
  var charset="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
  if(this.length=="")return "";
  for(var i=0,t,l=this.length,binstr="";i<l;i++){
	t=this.charCodeAt(i);
	if(t>255)return null;
	binstr+=("00000000"+(t.toString(2))).substr(-8,8);
  }
  l=binstr.length;var base64str="";
  for(i=0;i<l;i+=6)t=binstr.substr(i,6),base64str+=charset[parseInt((t+"000000").substr(0,6),2)];
  var requiredPadding=(6-t.length)/2;
  if(requiredPadding==1)base64str+="=";
  else if(requiredPadding==2)base64str+="==";
  return base64str;
}


String.prototype.base64_decode=function(){
  var charset="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
  if(this.length==0)return "";
  if(this.match(/[^a-zA-Z0-9\+\/\=]/))return null;
  var base64str=this.replace(/[^a-zA-Z0-9\+\/]/,"");
  for(var i=0,l=base64str.length,binstr="";i<l;i++)
	binstr+=("000000"+charset.indexOf(base64str.charAt(i)).toString(2)).substr(-6,6);
  l=binstr.length;var str="";
  for(i=0;i<l;i+=8)str+=String.fromCharCode(parseInt((binstr.substr(i,8)+"00000000").substr(0,8),2));
  return str
}


This an other protypes can be found at:
// From: http://www.webdevelo...7143#post347143
Was This Post Helpful? 0
  • +
  • -

#6 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 129
  • View blog
  • Posts: 832
  • Joined: 25-October 08

Re: Cut-and-Paste from one TEXTAREA to another TEXTAREA in the same form ?

Posted 30 November 2009 - 09:31 PM

Quote

newbie01.php just thanked you for this post!

Comment: <i>Thanks for your suggestion</i>


Could not PM you because your box is full (?)

You're most welcome.
Glad I could help.
Good Luck!
:)
Was This Post Helpful? 0
  • +
  • -

#7 newbie01.php  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 09

Re: Cut-and-Paste from one TEXTAREA to another TEXTAREA in the same form ?

Posted 03 December 2009 - 03:41 AM

View PostJMRKER, on 30 Nov, 2009 - 08:31 PM, said:

Quote

newbie01.php just thanked you for this post!

Comment: <i>Thanks for your suggestion</i>


Could not PM you because your box is full (?)

You're most welcome.
Glad I could help.
Good Luck!
:)


Thanks again, the prototypes are very good.

your box is full (?), hhhmmm, if you are referring to the Dream.In.Code mailbox, don't have one, I think that is what the PM try to send it to if am not mistaken? Am I correct with that assumption or does the PM supposed to send it to your registered email address?

Don't have enough dough yet to get a paid subscription ... :)
Was This Post Helpful? 0
  • +
  • -

#8 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 129
  • View blog
  • Posts: 832
  • Joined: 25-October 08

Re: Cut-and-Paste from one TEXTAREA to another TEXTAREA in the same form ?

Posted 03 December 2009 - 08:30 AM

View Postnewbie01.php, on 3 Dec, 2009 - 02:41 AM, said:

...
your box is full (?), hhhmmm, if you are referring to the Dream.In.Code mailbox, don't have one, I think that is what the PM try to send it to if am not mistaken? Am I correct with that assumption or does the PM supposed to send it to your registered email address?

Don't have enough dough yet to get a paid subscription ... :)


The moderators may correct me, but this is my assumptions about this forum:
1. The PM I was using is in this forum as I have no other means to contact you.
2. I don't think it requires "a paid subscription" to use the mail or forum.
3. If I were required to pay to help someone out and not be rewarded beyond my ego,
I don't think the forum would be a popular as it is!

Anyway, appreciate the "Thanks" ... good luck!
:)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1