Solved

retrieving field values from one form to another

Posted on 2004-08-20
10
185 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

16 Experts available now in Live!

Get 1:1 Help Now