How to use javascript split in Qualtrics - javascript

Very new to Javascript and have been searching the webs for assistance, but haven't quite found a solution.
I am attempting to use javascript to split/remove the output of a particular field. The data in the survey is being pulled from our school's database after a user logs in to the survey via shibboleth. All the information is being displayed, so that part works, but one particular field is appending an email address (#email.com) to a field.
I want to omit this part from being displayed. Either my javascript is incorrect or the javascript is not being loaded/read. The javascript code was borrowed from a colleague and it works on his surveys, but he has a lot of other things going on in his survey and this works for him.
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var iid = "${e://Field/theUTIID}";
var split_array = iid.split("#",1);
var eid = split_array[0];
Qualtrics.SurveyEngine.setEmbeddedData('theUTIID', eid);
});
Qualtrics.SurveyEngine.addOnReady(function()
{
/*Place your JavaScript here to run when the page is fully displayed*/
var iid = "${e://Field/theUTIID}";
var split_array = iid.split("#",1);
var eid = split_array[0];
Qualtrics.SurveyEngine.setEmbeddedData('theUTIID', eid);
});
I have this in both the Onload and OnReady for testing. Doesn't matter if I have this is one location or the other, I am not getting the desired results.
I only have one question on the survey (it's just a test survey) and so the javascript code is with the first and only question.
Survey Question has the following in a text entry. Again, output is displayed, but need the #email.com to removed from the EID field.

The code looks correct (other than it only needs to be in one or the other function). I'm guessing it isn't a problem with the code, but where you are trying to pipe the embedded variable. The JavaScript above has to be attached to a question on a separate page before the place where you want to pipe it.
Add a page break, then pipe theUTIID into a question on the next page.

Related

trying to populate a "shortcode" value in wordpress with javascript [duplicate]

This question already has answers here:
How do I pass JavaScript variables to PHP?
(16 answers)
Closed 5 months ago.
as stated, I am trying to dynamically populate a [shortcode] value in WordPress so that it puts the appropriate value in the field before it dumps the shortcode and all of the scripting happens in the plugin that outputs the complex code.
as of right now, I am able to properly output the value i want as seen here:
var url = window.location.href;
url = url.split('#').pop().split('?').pop().split('docsid=').pop();
var page = url.substring(url.lastIndexOf('/') + 1);
var docsid = ('"' + page + '"')
console.log(docsid);```
This works as expected, my problem is, i'm trying to populate this field:
document.write(real3dflipbook id=docsid);
based on the code that the shortcode is dumped to, it looks like the shortcode is running first, then attempting to run my inputted javascript.
I have to console.logs running; one within the page itself, another in the embed.js file
the embed.js file console.log is working as it should be and that is the value output i'm hoping to get from my code.
1_633dbda152374 embed.js:144:16
the documents console.log is kicking up an error that it is producing from the embed.js file whenever i try to document.write(real3dflipbook id=docsid)
Uncaught SyntaxError: expected expression, got '<' documents:607:15
The code from the embed.js that I believe is where it is getting hung up is here:
var containerClass = bookContainer.attr("class")
var containerId = bookContainer.attr("id")
bookContainer.removeClass(containerClass).addClass(containerClass + "-" + containerId)>
console.log(containerId);
here is what the output code ends up looking like in the final page:
don't have enough points to embed yet
the top bit of highlighted garbage in the image is what happens when i attempt to document.write();
the bottom bit highlighted in blue is what SHOULD happen if it were properly updating the shortcode.
Any ideas or solutions on this? any help would be greatly appreciated!!
You can not just insert a shortcode parameter via javascript. The shortcode is rendered by the backend on page load. To dynamically set shortcode params you would need to make an AJAX call to a custom function in the backend which returns your shortcode with the specified parameters.
More information on Wordpress AJAX can be found here https://codex.wordpress.org/AJAX_in_Plugins

jQuery - replicate date from field 1 to field 2

I'm currently looking to run a simple script using jQuery and TamperMonkey as I'm doing a recurent job which is time consuming and that should be pretty basic, not sure how to achieve the below (I've recorderd a gift) - I'm new to jQuery/coding, but searching arround, using this:
//Get
var IPG = $('#txt_name').val();
//Set
$('#txt_name').val(IPG);
might be where to look at?
the script should scan the field IPG ID where -1 are present, copy the name from the channel description and copy it to IPG description
https://gyazo.com/f4bd243827df598edfdd78ec1a2d53b5
any help in achieving this would be appreciate,
many thanks,
I named HTML elements' ids by myself because I simply don't know what are those fields' id named in your app.
What you are trying to achieve it is really simple and this code can do you the trick:
var IPG = $('#IPGid').val();
if (IPG==-1)
{
var toCopy = $('#ChannelDescription').val();
$('#IPGDesc').val(toCopy);
}
Note:
This can only be done once the page is loaded it is not live for every action.
This cannot treat all lines of the table you should figure your way out of how turning it dynamic to the whole table.

sharepoint Online/365 Jquery, Set Lookup Column Not working e.i ($("select[Title='Column']")

I've been doing some work on Sharepoint Online/365 and have got stuck trying to set the value of a lookup or choice column in NewForm.aspx
Narrowed my problem down to not being able to set lookup/Choice Columns
I have simplified a code on my page down to
//Phase being a Choice Column & Closure a case sensitive valid option
$("select[title='Phase']").val("Closure");
//ProjectName being a Lookup Column & Test2 a case sensitive valid entry in the list
$("select[title='ProjectName']").val("Test2");
I have no problem setting text fields as the following code works fine on a text field I created
$("input[title='TextField']").val("Test2");
I have used the following Jquery libraries 1.7.2/min.js and 1.11.3
Not sure whether you used _spBodyOnLoadFunctionNames.push() method for your logics. Usually you have to wait all SharePoint DOM objects are loaded and then to execute your jQuery code. If you used SharePoint JavaScript library, you probably needs to call ExecuteOrDelayUntilScriptLoaded() to make sure your call is called after curtain SharePoint .js files are loaded.
First Thanks "Verona Chen" and " DIEGO CARRASCAL" because of who i've learnt a few other tricks in SharePoint which will help with other projects.
My original script before the question was trying to use a query string to populate a field in newform.aspx (which i have done on sharepoint 2013 with code i have found here on)
Unforuntaly with sharepoint online/365 This code was no longer working.
This code has fixed my issue (though it does change how a few previous pages are constructed)
Appologies if this doesn't directly answer the above question (as this was me trying to breakdown the overall issue i was having into something simpler and easier to address based on me narrowing down the issue in my original code) however as I am now up and running, it seems only polite to post the outcome.
Prior to code, i have a projects list with a "ProjectName" field. I was sending the field name into a URL and querystring to get mylist/newform.aspx?ProjectName=Test2
I was then trying to pull that Test2 into the lookup field (liked to the project list) "ProjectName" in the list "MyList"
But even when loading the function for my old script with _spBodyOnLoadFunctionNames.push() it wasn't working.
After playing with this for a while and after some looking around i found this peice of code
<script type="text/javascript">
(function () {
var ctx = {};
ctx.Templates = {};
ctx.Templates.Fields = {
'ProjectName': {
'NewForm': renderTaskCategory
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();
function renderTaskCategory(ctx) {
//extract cat parameter from a query string
var GetProjID = GetUrlKeyValue('ProjID');
//set lookup field value
ctx.CurrentFieldValue = GetProjID;
//default template for rendering Lookup field control
return SPFieldLookup_Edit(ctx);
}
</script>
This means that i have to change my previous url builds to create mylist/newform.aspx?ProjID=2
This script then finds item ID 2 (which happens to be test2 in this case) and puts the title of item 2 in my lookup field ProjectName
Thanks again to those that helped earlier.
And apologies again if this doesn't directly answer the question i originally asked.

How to enter text in Slickgrid cell

I am working on an AngularJS app that has a Slickgrid on it. I am trying to write a test and im running into a problem. When I use Selenium I can get it to click in one of the cells but the sendkeys function doesn't seem to do anything, no text is entered even though I can see the cursor flashing in the cell.
Even if I record my actions in Selenium IDE, no actions are recorded for entering text in the cell.
I've tried opening the JavaScript console in chrome and writing some JavaScript to enter some text in one of the cells and made zero progress (I don't know JavaScript).
What JavaScript can I use in the chrome console to enter text in one of the cells? Does selenium not work well with SlickGrid?
I'm not sure what the best approach is here.
Thanks
It seems that you are asking about two things at once. I will try to emphasize that I have no experience in Selenium, but I can try answering the JavaScript part.
You didn't share too much information about your actual SlickGrid setup, so my solutions for your question are based on the official SlickGrid: Making it editable example, which you could try these methods on, for instance using the JavaScript ScratchPad.
I will share the two methods I have found, since I don't know which one could you integrate to your Selenium setup.
Method 1 - via the SlickGrid API:
var row = 0;
var cell = 0;
var test_input = 'Your input';
if(grid.canCellBeActive(row, cell)) {
grid.setActiveCell(row, cell);
grid.editActiveCell();
var activeCell = $(grid.getActiveCellNode());
if(typeof activeCell !== 'undefined') {
activeCell.children(0).val(test_input);
grid.gotoCell(row, cell);
}
}
Method 2 - via setting the data source of your grid.
In this case it's a JavaScript array of objects:
var row = 0;
var test_input = 'Your input';
data[row].title = test_input;
grid.invalidateRow(row);
grid.render();
These two methods both change the given cell data, the main difference is that using the second method you need to rely on the field name property you want to set.

Javascript, HTML, and iFrames

We have a web based type application which controls workflows for my place of business. Setting up how each user interacts with the application (Basically a web page) is a pretty straight forward process. We have the option of adding iframes into the layout.
I have written a very basic bit of javascript which sits inside an onChange function (part of the program) the script just calculates some numbers together and returns the value in a field.
What I am trying to do is get that total sum into an iframe instead of a form/element (?)
I understand this isn't very clear but is hard to go into great detail for company policy reasons.
Information is taken and calculated
for (var i = 0; i < grid.contentWindow.GetRowCount(); i++)
{
Numof = grid.contentWindow.GetSingleColumnValue(i, 'info').replace(re, "");
total = parseFloat(Numof) - total;
And is printed out into a pre created field using
CF_SetFieldValue("Printed_Field", dec_ToDecimalValue(total.toString(), 2));
Question is: how do I get the information to print in the iframe instead of "Printed_Field"?
Sorry for the lengthy and randomish post. any help would be much appreciated.
Edit: I guess at the most simplest question - How do I get the information in the forms into the inframe instead? (To be displayed in a table)
That depends on how CF_SetFieldValue is defined. By the looks of it there's a lot of very strange and probably superfluous functions that get in the way of easy-to-read-and-understand code.
Probably what you need is something like grid.contentDocument.getElementById('Printed_Field').value = dec_ToDecimalValue(total.toString(),2);

Categories

Resources