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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java script for copying values from one form to another

Status
Not open for further replies.

MavrickStl

Programmer
Feb 20, 2001
71
US
Guys,

Is it possible to copy values from FORM - B (text field) to another form FORM - A (text field) using checkbox (on FORM -B) as selection criteria? Can someone point to me a sample code? . Form A and FORM B will be opened in different browser windows.

FORM B will have a submit button users can click after they have selected check box as their selection criteria, which will be located in front of text boxes on FORM - B.

Thanks,

Mav
 

Using window.opener, a popup can talk to its opener window. If both your Form A and Form B popups share the same opener, then what you ask is easily achieved.

If, when you open each window, you store a handle to it in a global variable, you can call a function in the opener window to copy the data for you:

Code:
var winAHandle = winBHandle = null;

function openWinA() {
   winAHandle = window.open(args);
}

function openWinB() {
   winBHandle = window.open(args);
}

function copyDataFromAtoB() {
   if (winAHandle != null && !winAHandle.closed) {
      var FormA = winAHandle.document.forms['formName'].elements;

	   if (winBHandle != null && !winBHandle.closed) {
		  var FormB = winBHandle.document.forms['formName'].elements;
		  // do stuff here with the elements of forms A and B
		  // for example, if both had a field called "data", this
		  // would copy the value of data from form b to form a:
		  FormA['data'].value = FormB['data'].value;
	   } else {
		  alert('Error accessing Form B');
	   }
   } else {
      alert('Error accessing Form A');
   }
}

So the popup would call:

Code:
window.opener.copyDataFromAtoB();

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
Hi cLFlaVA,

I am using ASP. Form A contains several textarea fields. Data in textarea field is resulting from SQL statements - querying a Oracle DB.

Let's say Form - A contains weekly status report for week 10. Form - A will have a button at the bottom called COPY. If user hits that button a new browser windows will open with data from week 9 (let's call it form B). If a users has a similar task item for week 9 and week 10 then he should not have to type that task item for week 10. He should be able to copy it from week 9 i.e. let's say form B. Form B will contain textarea and checkboxes next to them. Data will be copied from TEXTAREA1 on form B (week 9) to TEXTAREA1 on form A (week 10) if checkbox in front of TEXTAREA1 form B is checked. Form B will have a button at the bottom called copy. Users will click on this button once they checked the items they want to copy to form A.

Please let me know if you have any further questions.

I appreciate you help.

Mav
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top