Calling javascript method

I have a application running on web. In this application

I have a form with a link on it. This link calls a javascript function which opens a view in new window. Javascript code used is

window.open(url, windowname, other_parameters);

This view has 3 columns. Out of these 3 columns, 2nd column has formula

“[input type="checkbox" name=“checkboxname” value="”+ codenumber + "" onClick="javascript:add(this.value)">] "

Javascript function “add” adds selected document’s “codenumber” fields value in a particular field (say “listing”) on form. Javascript function add is as given below.


function add(val){

var f = window.opener.docuemt.forms[0] >>line1

f.listing.value=f.listing.value + " \ ; " + val; >>line2

window.opener._doClick(‘$Refresh’,this,null,null) >>line3

}


This javascript method is in the JSHeader of the $ViewTemplate form of this view.

This works fine for selecting individual document from view by checking the checkbox. I want a functionality wherein I can provide user with a button/ link by clicking on which all the documents will be processed by the javascript method “add”.

I tried to put formula hotspot link titled ‘Select All’ on $ViewTemplate form of this view. On this link I wrote the code to call javascript method, using @URLOpen

@URLOpen(“javascript:add(parameter)”) (Initial try to invoke javascript method from link)

When I tested this link, the control got moved to javascript function, but the code didn’t added the values to fields. Even I tested by adding alert aft line2 of add method. Alert appeared as expected but the code didn’t added the values to the listing field.

Can anyone help me in this regard. The same code is working when getting invoked from checkbox’s Onclick event? So while invoking it from $ViewTemplate form am I making any mistake? Is there any other way to achieve this?

Waiting for responses.

Thanks in advance.

Harshad :slight_smile:

Subject: calling javascript method

this.value works because when you click on the check box, “this” refers to checkbox and then you can retrieve the value using “value” method.

For getting values of all the checkboxes then you need to loop through all the checkboxes and then get the value of the checkbox and then add the same to the text field on the document.

“this.value” code will not work in this case.

So, write a new function which will loop through all the check boxes and then writes its value.

–Phani

Subject: RE: calling javascript method

Hi Phani kiran,

thanks for your prompt reply.

What you are saying is absolutly fine. But where should I write this code, shall I write this code on the link on $TemplateDefault form of this view?

One more thing, I am unable to trace out (as I am new to Javascript) is,

while creating the view, I am creating those checkboxes so all these checkboxes will have same name. So how can I access them in the code.

Please help. Waiting for replies. Thanks in advance.

Harshad :slight_smile: