AnsweredAssumed Answered

How do I add a field value to button onclick javascript

Question asked by brettando on Nov 28, 2018
Latest reply on Dec 9, 2018 by brettando

I've got a Calculated field called: calcID with dynamic string number displayed, example result: 12.

I need to add this to a button's onclick event, which opens up a newform.aspx in dialog and that calcID is added to the URL as a query string parameter. ?CID=12

I've got the dialog opening up with a newform.aspx but have no idea how to add the value from the calcID.

Client click:

javascript:portal_openModalDialog('/sites/Programs/res/Lists/Contractors%20Charge%20Codes/NewForm.aspx?CID=+calcID+');javascript:return false;

So the value CID=xxxx is to be in the URL Query string, so it can be added to the newform where a field called CID is displayed. So all I need is a way to store that 12 in a variable and add it to the CID parameter.

 

My code in the Custom Javascript to display the dialog box is as shown below.

The Dialog box displays but the variable for thiscalcID does not. I believe it's to do with the JavaScript syntax formatting of the URL. I am not that great with JavaScript, so any help would be great. Thanks.

function portal_openModalDialog(strPageURL) {
var thiscalcID = NWF$("#" + newcalcID).val();
var options = SP.UI.$create_DialogOptions();
options.url = "'/sites/Prog/res/Lists/Contractors%20Charge%20Codes/NewForm.aspx?CID=" + thiscalcID +" ' ";
options.title = "Add New Charge Code";
options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
SP.UI.ModalDialog.showModalDialog(options);
}

Outcomes