SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast akstar's Avatar
    Join Date
    Feb 2009
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to send data from one text box to another text box ?

    I think the solution will be in Ajax.
    Sorry, wrong place
    Last edited by akstar; Mar 23, 2009 at 10:48.

  2. #2
    SitePoint Member nacker4it's Avatar
    Join Date
    Mar 2008
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you use php so it is easy to put value from one textbox to another textbox.
    here is example:
    <form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
    <input name="txt1" type="text">
    <input name="txt2" type="text" value="<?=$_POST['txt1'];?>">
    <input tyle="submit" name="submit" value="submit">

    Javascript, jquery and ajax also can be used for this purpose!

  3. #3
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just Javascript, not Ajax.
    If you want to copy from one text to another add a blur listener to the first text box and update the .value of the second if it's blank.
    jQuery is probably a good choice for this (to add listeners, select DOM elements)

  4. #4
    SitePoint Member
    Join Date
    Mar 2009
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    This is a solution in Javascript for two input and also span.

    For search element i do by id. id should be unique on the same page

    Code XML:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    	<head>
    		<title>Copy test</title>
    		<script type="text/javascript">
    			var laurent;
    			function swap_input(source, target)
    			{
    				var buffer = document.getElementById(source).value;
    				document.getElementById(source).value = document.getElementById(target).value;
    				document.getElementById(target).value = buffer;
    			}
    			function swap_html(source, target)
    			{
    				var buffer = document.getElementById(source).innerHTML;
    				document.getElementById(source).innerHTML = document.getElementById(target).innerHTML;
    				document.getElementById(target).innerHTML = buffer;
    			}
    			function docopy()
    			{
    				swap_input("source_1", "target_1");
    				swap_html("source_2", "target_2");
    				laurent = document.getElementById("source_2");
    			}
    		</script>
    	</head>
    	<body onload="javascript:docopy();">
    		<form action="?" method="post">
    			<div>
    				<input id="source_1" value="Source 1" />
    				<input id="target_1" value="Target 1" />
    			</div>
    		</form>
    		<div>
    			<span id="source_2" style="color: #FF0000;">No an input</span>
    			<span id="target_2" style="color: #0000FF;">Still not an input</span>
    		</div>
    	</body>
    </html>

  5. #5
    SitePoint Enthusiast akstar's Avatar
    Join Date
    Feb 2009
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you very much for the replies.
    I will look into them and test it out =D


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •