gajubhai Posted May 13, 2010 Share Posted May 13, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/201610-manipulating-text-box-using-php/ Share on other sites More sharing options...
phpchamps Posted May 13, 2010 Share Posted May 13, 2010 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=""> Quote Link to comment https://forums.phpfreaks.com/topic/201610-manipulating-text-box-using-php/#findComment-1057651 Share on other sites More sharing options...
Muddy_Funster Posted May 13, 2010 Share Posted May 13, 2010 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> '; //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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/201610-manipulating-text-box-using-php/#findComment-1057661 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.