Simple java question

Hi experts,

I'm trying to use some Javascript to get some things done in my web enabled application.

I want to extract the value of a field in a document (DocUniqueID) and paste this value in a function that will open a new window.

for extracting the data from the field I'm using this code in the JS Header:

function extractDocId () {
    id=window.document.forms[0].DocUnqiueIDTxt.value
    alert(id)
}

The alert is there to check it's value for debugging.

In a click event I'm calling the extractDocId function and the document is present in a frameset of three frames.

When I check this on the web, errors occur even when I remove the alert(id). I think it has something todo with the frames, because when I use the same code in a test database, whitout use of frames, this code is running.

AND...

Let's say the previous code is running, how do I get the variable "id" in the URL I want to open. Is is something like this ?

newWindow=open.window("http://domino1.test.nl/db.nsf/" + id + "/$FILE/attach.doc?OpenElement")

You see, I want to open a attachment from a specific document in a new window...

Greetings,

Bob
LVL 1
oosterbaanAsked:
Who is Participating?
 
Jean Marie GeeraertsApplication EngineerCommented:
Nope, in Internet Explorer 5 word documents can be opened inside the current window. Anyway, if it's to be a fixed link to the attachment from within the document I normally use a very simple HTML-link passthrough like
[<A HREF="URL">descriptive text</A>]
which I calculate using computed text.

Bob,
I may have a suggestion for a formula you can use in a comupted text to display a list of attachments as hyperlinks in read mode and as checkboxes in edit mode to be able to remove selected attachments. :

@if(!@Attachments; @Return(""); "");
@if(@IsDocBeingEdited;
"[<b>Select attachments to be removed:</b><br>] +
@Implode("[input type=\"checkbox\" name=\"%%Detach\" value=\"" + @AttachmentNames + "\">" + @AttachmentNames; "<br>]");
"[<b>Attached documents</b><br>]" +
@Implode("[<a href=\"" + @Text(@DocumentUniqueID) + "/$file/" + @AttachmentNames + "\">" + @AttachmentNames + "</a>";"<br>]))

The above code will use the name of the attachments and add the necessary html-code using the @implode function to display the checkbox list in edit mode and the list of hyperlinks in read mode.
Looks complicated, but when you know HTML and you break down the code to it's seperate elements it's quite straight-forward.

Anyways, let us know if you get it working.
0
 
HemanthaKumarCommented:
You are coorect frames and document have their own place in JS DOM

To refer a field value in a frame use this

parent.frames[0].form.field1.value

Where 0 is the index of the frame from top left to bottom right, instead of 0 u can give the frame name, this will extract the value appropriately and use that doc id value in the url that u mentioned last


~Hemanth
0
 
Jean Marie GeeraertsApplication EngineerCommented:
You can leave out the window classification in your command and the problem will no longer exist.

To get the value, you need to have your function return the extracted value.

Here's the complete JavaScript :
In the JS Header:
function extractDocId()
   {
   return document.forms[0].DocUniqueIDTxt.value;
   }

In your onclick event to open the new url :
newWindow=open.window("http://domino1.test.nl/db.nsf/" + extractDocID() + "/$FILE/attach.doc?OpenElement")

Also keep in mind that the field has to be on your form as a field for you to be able to reference the value. If it's a computed field for example, you also need to check the "Generate HTML for all fields" option on the second tab of the form properties.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
zvonkoCommented:
ha ha ha...

very well boys and girls; but absolutely unnecessary <|;-)

Instead of doing this complicated transfers in JavaScript simply allow Domino to generate the JavaScript code as passtru text.
Either make it ComptedText or embed a field to produce this DocId. Or even better: do not fetch the attachment by docid but by a view with first column sorted with @AttachmentNames.

Do you need a more detailed instruction or are this ideas enough for you Bob?
0
 
oosterbaanAuthor Commented:
It's not possible for me to create a view that is sorted with @AttachmentNames, because all the attachments have the same name...

Whatever I do to extract the value of the Field I get a error message whitin the browser, that saying that document.form.DocumentUniqueIDTxt is not a object. I have tried different variants, removed the form out of the frame, set the option "generate HTML for all fields"..nothing worked

I have tried:

document.form[0].DocumentUniqueIDTxt.value
document.form.DocumentUniqueIDTxt.value
window.document.DocumentUniqueIDTxt.value


0
 
zvonkoCommented:
the format document.form[0].DocumentUniqueIDTxt.value is valid only if you can see this value in html source code like this:
<input type=hidden name=DocumentUniqueIDTxt value=FFFFF >

(if you see only the value on the page but not in html input vars than it is a plain text and not a variable accessible by JavaScript).

0
 
Jean Marie GeeraertsApplication EngineerCommented:
You forgot my last remark, Bob. Check the checkmark next to "Generate HTML for all fields" on the second tab of the form properties dialog box. This will always create the input field in the browser. When the document is opened for reading it will be hidden, but still accessible for JavaScript.
0
 
oosterbaanAuthor Commented:
Hi guys,

I did set the option jerrith (read my previous comment) and I have checked in the source if the line was present (like zvonko said) and it was exactly there...

I have used this code:

document.form[0].DocumentUniqueIDTxt.value

but the result in the debugger is saying:

Error: document.form.0'is not a object

Phhhhhh...Java isn't as simple as they said

Greetings,

Bob
0
 
Jean Marie GeeraertsApplication EngineerCommented:
You need to put document.forms[0].DocumentUniqueIDTxt.value

The extra s is important. document.form does not exist, document.forms does.
If you made this typo only in posting the comment, but not in your actual code, where is your code located ? In a hotspot/button on the form ?
0
 
zvonkoCommented:
good JM. ;-)

I was also cut'n&pasting upper code and oversee missing document's S :-)

...but still my opinion is that this all is wrong strategy. As soon as Bob state where he want to call this window.open(URL) and why he want to call window.open(URL) the explanation how to produce this window.open(URL) will be easy for me.

Until now Bob state he want to open attach.doc This looks like WinWord document. They are never oppened inplace, always as new window. So this JavaScript window.open(URL) is unnecessary, 'cose simply URL would be enough...

Let's look for more details...

So Bob please explain more in datail wath do you need this code for and wath do you like to gain with it.

0
 
Jean Marie GeeraertsApplication EngineerCommented:
P.S.: Sorry for the error before, I forgot the extra 's' when posting so, it's my fault it wasn't working.
0
 
oosterbaanAuthor Commented:
Thanks guys for all your comments, but it's working fine now. The S was the "problem" (-:
BTW...I don't want to open a .doc file, but a .pdf file only on the web. The function I'm trying to achief is when a document is opened (on the web), the attachment present in this document will open automaticly whitin a seperate window, so I thought to write a Javasript, that will run OnLoad...

If you have other suggestion, please let me know....

Greetings,

Bob
0
 
oosterbaanAuthor Commented:
You both deserve points, so I will open a dummy question for zvonko to give him his points...

Greetings,

Bob
0
 
zvonkoCommented:
Thank you Bob for your offer, but do not make me ashaimed...

The only thing I did was sarcasm, real work was done by JM.

So please delete the other points. I do realy need points, but not this way, OK <|;-)

Greetings,
zvonko
0
 
oosterbaanAuthor Commented:
Hi zvonko,

Your a good human (-:

I hope to see you in my next questions with or whitout your sarcasm (-;

Greetings,

Bob
0
 
zvonkoCommented:
wath does mean "good human"? I only take care about my wizzard image <|;-)  (hi hi :-))
0
 
Jean Marie GeeraertsApplication EngineerCommented:
I just got back from my holliday. Thanks for the A, Bob!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.