1
votes

I would like to pass values of 4 fields in to new XPages with ClientSide JavaScript

Find below what i tried so far, I cannot put values into field in the new XPages :(

//Client Side JS pass values to the new window

var cFld = document.getElementById("#{id:fieldNameID}").innerHTML ;
myUrl = "http://serveradres/applicationame.nsf/xspFrmTest.xsp?action=newDocument";
var zWindow = window.open(myUrl, '_blank');
var zDoc = zWindow.document;
zDoc.getElementById("#{id:fieldNameID2}").value = "TEST VALUE";

UPDATE 1: the new page i would like to open is in the another application. So i cannot carry any values with any type of scopes (Application, session, etc...) thinking about sample below. From xspfrmtest.xsp to xspfrmtest2.xsp

  1. Application1.nsf -> xspfrmtest.xsp
  2. Application2.nsf -> xspfrmtest2.xsp
1
Why not add these field values to the SessionScope and read the these values from the SessionScope in the new XPagesFrank van der Linden
Why is there a space after zWindow - "var zDoc = zWindow .document; zDoc.document.getElementById("#{id:fieldNameID2}").value = "TEST VALUE";" AND why are you calling .document twice?pipalia
Keep in mind that referencing with "#{id:fieldname}" only works for components/fields on the current XPage. I would use the approach of @FrankvanderLinden (see comment above), but if you want to exclusively use client-side JavaScript you would have to write something like this: zWindow.document.querySelector('[id$=":fieldname"]').value="TEST VALUE";xpages-noob
@pipalia This is just a copy paste mistake. In my page the code is correct.Cumhur Ata
PS: You could also provide the field values as url parameters (for example ...&field1=value1) and set the computed value of the target component to #{param.field1}.xpages-noob

1 Answers

1
votes

This is an example for transferring (large) field values between XPages of different Domino databases on client side:

Database One.nsf with XPage One.xsp:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view
    xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:inputText
        id="fieldOne"></xp:inputText>
    <xp:button
        value="Open Two.xsp in Two.nsf"
        id="button1">
        <xp:eventHandler
            event="onclick"
            submit="false">
            <xp:this.script><![CDATA[
                window.open("http://server1/Two.nsf/Two.xsp", '_blank');
            ]]></xp:this.script>
        </xp:eventHandler>
    </xp:button>
</xp:view>

Database Two.nsf with XPage Two.xsp:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
    <xp:eventHandler
        event="onClientLoad"
        submit="false">
        <xp:this.script><![CDATA[
            var fieldOne = window.opener.document.querySelector('[id$=":fieldOne"]');
            if (fieldOne) {
                window.document.getElementById("#{id:fieldTwo}").value = fieldOne.value;
            }
        ]]></xp:this.script>
    </xp:eventHandler>
    <xp:inputText 
        id="fieldTwo"></xp:inputText>   
</xp:view>

The second XPage uses window.opener onClientLoad to get a handle to first XPage's window and reads field values from there then.