Jump to content

Recommended Posts

Hi..

  I am new to php. I want to try simple application.  My form contains two empty text boxes and one button name copy. Can anybody tel me the php script for copying data from one textbox to other? Suppose I typed "Hello world!" in texbox1 and clicked copy button then textbox2 shoul also display "Hello world!"

 

Please help.

Link to comment
https://forums.phpfreaks.com/topic/201610-manipulating-text-box-using-php/
Share on other sites

Firstly, in your program you dont need php... it can be done by using html and javascript..

 

<script language="JavaScript1.2" type="text/javascript">
function copyText(){
if(document.getElementById("txt_text1").value != ''){
	document.getElementById("txt_text2").value = document.getElementById("txt_text1").value;
}else{
	alert("Nothing To Copy");
}
}

</script>

<input type="text" id="txt_text1" name="txt_text1" value="">
<input type="button" name="btn_copy" value="Copy" onClick="copyText()">
<input type="text" id="txt_text2" name="txt_text2" value="">


Here's some commented code on how to do it in php:

<?php
if (!isset($_POST['text1'])) //check to see if first load of page
{
$text2 = '<textarea name="text2" readonly="true"></textarea><br>'; //show empty text area if first load 
}
else{
$text_content = $_POST['text1']; // when not first load assign text from text area1 to this variable
$text2 = '<textarea name="text2" readonly="true">'.$text_content.'</textarea><br>'; //show text area with text from first text area in it
}
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post" type="submit">'; // reload this page when button is clicked
echo '<textarea name="text1"></textarea>&nbsp'; //make first text area
echo $text2; //make second text area
echo '<input type="submit" value="Move" />'; //make button to perform proccess
echo '</form>'; //end the form
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.