[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

retrieving field values from one form to another

Posted on 2004-08-20
10
Medium Priority
?
209 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 2000 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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
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
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

591 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