Solved

retrieving field values from one form to another

Posted on 2004-08-20
10
187 Views
Last Modified: 2013-12-18
Hi all,

For my web application, I have form1 and form2. I have a bunch of fields in both the forms. Is it possible for me to display the field values of form1 in form2
For example: if i have a field "company1" in form1 and the user enters its vaLue in the browser and it gets saved.
Now, is there any way i can automatically display the value of field "company1" in the field "company2"(of the form2) ,when the form2 is opened in the browser?

Any responces greatly apprecited.

thanks
J  
0
Comment
Question by:jaggernat
  • 7
  • 3
10 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 11861502
There is a pure JavaScript version for that problem using Cookies.
And a second variant using @Formulas and ProfileDocuments.

I would recommand the Cookie method. Are you interested?

0
 
LVL 10

Author Comment

by:jaggernat
ID: 11861744
yes , please ..i would appreciate it..

Thanks,
Jay
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 11862414
Ok, here a tested version:

Put this in Form1 JSHeader:

var fieldMap = ["Company1:company", "EmailAddress1:email","City1:city"];

function putFields(theForm){
   theForm = document.forms[0];
   cVal = document.cookie.split("sF=");
   if(cVal.length==2){
     cVal = unescape((cVal[1]+";").split(";")[0]);
   } else {
     cVal = "";
   }
   for(i=0;i<fieldMap.length;i++){
      fVal = theForm[fieldMap[i].split(":")[0]].value;
      cNam = fieldMap[i].split(":")[1];
      cVal = cVal.replace(new RegExp(cNam+"\\=[\\w\\% \\@]*\\:","g"),"");
      cVal += cNam+"="+escape(fVal)+":";
   }
   document.cookie="sF="+cVal+";path=/;";
}

Put this in Form1 onSubmit event:

 putFields(this)


Put this in Form2 JSHeader:

var fieldMap = ["Company2:company", "EmailAddress2:email","City2:city"];

function getFields(){
   theForm = document.forms[0];
   cVal = document.cookie.split("sF=");
   if(cVal.length==2){
     cVal = unescape((cVal[1]+";").split(";")[0]);
     for(i=0;i<fieldMap.length;i++){
        fNam = fieldMap[i].split(":")[0];
        cNam = fieldMap[i].split(":")[1];
         if(cPart=cVal.match(new RegExp("\\b"+cNam+"\\=([\\w\\% \\@]*)\\:"))){
            if(cPart.length==2) theForm[fNam].value = unescape(cPart[1]);
         }
      }
   }
}


Put this in Form2 onLoad event:

getFields()


Short description:
In Form1 does the Array  fieldMap contain pairs of Form1 field names (be aware of exact uppercase and lowercase characters) folowed by a colon and the name for that field in the cookie.
The name in the cookie is the field reference for any other form to get that field value not by the Field name like used in Form1 but by a normalized cookie field name.
So is the Array in Form2 also pairs with the Field names as used on Form2 and the coresponding cookie name.
You have not to use all Form1 fields in Form2. Only used field names will overwrite the Form2 fields and only if the cookie contains a value for that field.

Tell me how it works for you.

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11862441
Sorry, take better this function versions:


function putFields(theForm){
   theForm = document.forms[0];
   cVal = document.cookie.split("sF=");
   if(cVal.length==2){
     cVal = unescape((cVal[1]+";").split(";")[0]);
   } else {
     cVal = "";
   }
   for(i=0;i<fieldMap.length;i++){
      fVal = theForm[fieldMap[i].split(":")[0]].value;
      cNam = fieldMap[i].split(":")[1];
      cVal = cVal.replace(new RegExp(cNam+"\\=[\\w\\% \\@]*\\|","g"),"");
      cVal += cNam+"="+escape(fVal)+"|";
   }
   document.cookie="sF="+escape(cVal)+";path=/;";
}


And for Form2 this:
function getFields(){
   theForm = document.forms[0];
   cVal = document.cookie.split("sF=");
   if(cVal.length==2){
     cVal = unescape((cVal[1]+";").split(";")[0]);
     for(i=0;i<fieldMap.length;i++){
        fNam = fieldMap[i].split(":")[0];
        cNam = fieldMap[i].split(":")[1];
         if(cPart=cVal.match(new RegExp("\\b"+cNam+"\\=([\\w\\% \\@]*)\\|"))){
            if(cPart.length==2) theForm[fNam].value = unescape(cPart[1]);
         }
      }
   }
}


0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11862446
Sorry, one more improvement:

function putFields(theForm){
   theForm = document.forms[0];
   cVal = document.cookie.split("sF=");
   if(cVal.length==2){
     cVal = unescape((cVal[1]+";").split(";")[0]);
   } else {
     cVal = "";
   }
   for(i=0;i<fieldMap.length;i++){
      fVal = theForm[fieldMap[i].split(":")[0]].value;
      cNam = fieldMap[i].split(":")[1];
      cVal = cVal.replace(new RegExp(cNam+"\\=[^\\|]*\\|","g"),"");
      cVal += cNam+"="+escape(fVal)+"|";
   }
   document.cookie="sF="+escape(cVal)+";path=/;";
}


And for Form2:
function getFields(){
   theForm = document.forms[0];
   cVal = document.cookie.split("sF=");
   if(cVal.length==2){
     cVal = unescape((cVal[1]+";").split(";")[0]);
     for(i=0;i<fieldMap.length;i++){
        fNam = fieldMap[i].split(":")[0];
        cNam = fieldMap[i].split(":")[1];
         if(cPart=cVal.match(new RegExp("\\b"+cNam+"\\=([^\\|]*)\\|"))){
            if(cPart.length==2) theForm[fNam].value = unescape(cPart[1]);
         }
      }
   }
}



0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 10

Author Comment

by:jaggernat
ID: 11862682
hi,

sorry, the problem is  a one level more complex. i want to retrieve a field value from a stored document to a form in a browser.
For a clear description, here it is:
The value of "company" field (IIT) in this link    :   http://216.47.158.148/AMSStaff.nsf/ad2205b8b2c4ae4e86256e9b000e0553/142f6f40f11c2aa486256ef500605901?OpenDocument&Highlight=0,iit*     

should be displyed in the jobtitle field  in this form link:    


 http://216.47.158.148/AMSStaff.nsf/ApplyJobs?OpenForm

do i have to make any modifications.


thanks,
J
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11862858
Please assign for my work here the grade A and open a new question with more details.
My upper solution did exactly what you asked for in the original question.

I can help you with the new requirment and with the $$LoginUserForm
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11865523
Ok, thanks for points and grading.

You can open a new question for the changed requirment but I can give you the answer also here: the changed requirment is far too simple!
To get a value from one document to next Form you need NO scripting. It is a built in feature of Notes to inherit values from a document to a new documetn.
Check in the new Form a form property with the label: "FormulaInheritValuesFromSelectedDocument"
That property is the first checkbox in the propelar hat tab in Form properties.
So the only thing you have to do is to click that checkbox in your Form ApplyJobs in the AMMSStaff.nsf
After that you have to put in your Field "Subject" in the ApplyJobs Form this formula for the DefaultValue: company
That's all.




0
 
LVL 10

Author Comment

by:jaggernat
ID: 11866074
i did check the "FormulaInheritValuesFromSelectedDocument" form property in apply jobs and gave the default value of field"subject"  as company.

But it does not display the company value in the apply jobs form..
i am confused..
How does the apply jobs form(which is dynamic) retrieve value from the static document.


thanks,
J

 
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11866180
Please open a new question.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now