+ Start a Discussion
Puja ChoudharyPuja Choudhary 

pass a variable in a new window url

I have a variable 'd' that captures the current date time.
In the same page i have a button inside jquery which is redirecting to a new page in new window.
I want to pass the variable d  in the url.
Code:
var d = new Date();
The url is :   '<a href="/apex/vfp_KOT?oid=" class="js-newWindow" data-popup="width=500,height=600"><button type="button" class="btn btn-primary">Print KOT</button></a>&nbsp;&nbsp;&nbsp;&nbsp;'+

New Window :  
$(document).ready(function(){
            $('.js-newWindow').click(function (event) {
                event.preventDefault();
                var $this = $(this);
                var url = $this.attr("href");
                var windowName = "popUp";
                var windowSize = $this.data("popup");
                //alert($.session.get('sessionoid'));
                var noid = $.session.get('sessionoid');
                var urlnew = url+noid;
                window.open(urlnew, windowName, windowSize);
            });
        });
Jyothy KiranJyothy Kiran
Hi Puja,

Try this :

$(document).ready(function(){
            $('.js-newWindow').click(function (event) {
                event.preventDefault();
                var $this = $(this);
                var url = $this.attr("href");
                var windowName = "popUp";
                var windowSize = $this.data("popup");
                //alert($.session.get('sessionoid'));
                var noid = $.session.get('sessionoid');
                var urlnew = url+noid+'?dateValue=' + d;
                window.open(urlnew, windowName, windowSize);
            });
        });
Puja ChoudharyPuja Choudhary
hi Jyothi,
I tried this code...but it is not working....after modifying to this...the button is not clickable
Ishan.AroraIshan.Arora

Hi, Puja Choudhary
Use this code to pass the parameter in param1 variable

along with address of next page , in this case a vf page BankingTransaction

Note use any of 2 url style

1. String url='https://c.ap5.visual.force.com/apex/BankingTransactionManagement?core.apexpages.request.devconsole=1&param1='+ yourParameter;

in above if url has ? symbol in it already use & symbol to join parameter

2. String url='https://c.ap5.visual.force.com/apex/BankingTransactionManagement?param1='+ yourParameter;

if url has no ? symbol then add ? and parameter

public PageReference newRecord() {
        
        //initilizing pagereference
        PageReference pageRef;
        
        
        //using try catch block for error handling
        try {

                        // add url of new record page of your object
                         // cocatning parameter with url for parameter pass by url
                    String url='https://c.ap5.visual.force.com/apex/BankingTransactionManagement?core.apexpages.request.devconsole=1&param1='+ yourParameter;
                        
                        // page reference for new page
                        pageRef  = new PageReference(url);

        } 
        catch(Exception e)
        {
            
            ApexPages.addMessages(e);
            
            pageRef =  new PageReference('/apex/TransactionController');
        }
        
        Return pageRef;
    }

 

Please set as best answer if it works for you

Puja ChoudharyPuja Choudhary
Hi Ishan,
Can you suggest me something that can be done in my code.....also I want the new page to open in a new window.
Ishan.AroraIshan.Arora
use this example to pass parameter
window.location.href = "http://www.gorissen.info/Pierre/maps/googleMapLocation.php?lat="+elemA+"&lon="+elemB+"&setLatLon=Set";
Puja ChoudharyPuja Choudhary
hi,
If I change the code in the below line like:

<a href="/apex/vfp_KOT?datetime=+d+&oid=" class="js-newWindow" data-popup="width=500,height=600"><button type="button" class="btn btn-primary">Print KOT</button></a>

The value of "d" is not coming....Is there any problem in the syntax?