Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to update textarea with text field contents?

Status
Not open for further replies.

rhyno2k

IS-IT--Management
Jun 9, 2001
222
US
Hi,

I have a form that is designed to generate a shipment notification email to a customer. On the form is a text input field where the user will enter the package tracking number, e.g. 1Z 123 456...
Code:
<input size="16" id="trackingno" name="trackingno" value="" type="text" />

I want to add this number into the body of a textarea field -- which is where the body of the email message will reside.
Code:
<textarea id="messagebody" name="messagebody" cols="120" rows="14" disabled><?= $body ?></textarea>

Right now, I have the body of the message defined in PHP:
Code:
$body = "Dear Joe,

	Your widget has been shipped.  $carrier tracking number: $trackingno .
	
	You may track your package here:
	[URL unfurl="true"]http://wwwapps.ups.com/WebTracking/processInputRequest?InquiryNumber1=$trackingno[/URL]

...etc.";

How can I get the value of the "trackingno" input box into the textarea field (where the $trackingno variable currently is) without doing a page refresh -- either on-the-fly, or via JS "update tracking #" button?


Thanks,
--RHYNO
 
Here is an example you can edit. Hope this helps.
Code:
<html>
<script type="text/javascript">


function copyText(varTextInput){
	var varText = "Dear Joe,\n Your widget has been shipped.\n your tracking no is:" + varTextInput + "\n You may track your package here:[URL unfurl="true"]http://wwwapps.ups.com/WebTracking/processInputRequest?InquiryNumber1="[/URL] + varTextInput;
	document.getElementById("emailTxt").value = varText;
}
</script>
<head>
</head>
<body>
tracking no<input type="text" id="textInput">
<textarea id="emailTxt"rows="5" cols="20">

</textarea>
<button onclick="copyText(document.getElementById('textInput').value)">copy</button><br>
</body>
</html>
 
Hey J, that works nicely, thanks!

My next trick will be to insert the shipper's name (UPS, FedEx, etc.) into the same textarea based on a drop-down selection... I think I can work it the same way as you have here, using an onChange/onBlur in <SELECT>.

--RHYNO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top