Jump to content

manipulating text box using PHP


gajubhai

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
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.