So if any of you have any experience with scraping or particularly import.io it will help, since import.io is what i'm using... although I think my question is just about JS really...
I really just want to connect a basic html input to the import.io JS code so I can have a custom search
http://jsfiddle.net/LSng3/1/
"input": {
var search_name = document.getElementsByName("search_name").value;
"search_name": search_name
}
<input name="search_name" placeholder="doesnt work :(">
Heres my go... its the basic working import.io JS example. I tried to add a variable for the input name and add the variable as the search item but that alone isnt working...
I contacted the import.io team and they said they will try to make a easier tutorial in the future but for now try to look at the particle example they have which does include a input to search with but the example is too big for me to deconstruct just to see how the input works.
heres the particle example I uploaded to my server so you can see it working although its a bit slow-> http://www.originalengine.com/scrape/
Please find here a modified version of your code which seems to produce the correct result: http://jsfiddle.net/zNSbk/
This is the modified function:
var doTestQuery = function() {
// Query for tile myTestScrape2
var search_name = document.getElementById("myInput").value;
console.error(search_name);
importio.query({
"connectorGuids": [
"a2201b40-7acc-4a3d-a3ed-30e71e018ffa"
],
"input": {
"search_name": search_name
}
}, { "data": dataCallback, "done": doneCallback });
}
Steps that I took to get this working (not all may be required but it is a summary of what I was playing with):
Redefined the function called by the submit so there's no possible collision with the one that we defined in the script
Moved the creation of "search_name" variable out of the JSON argument to importio.query
Assigned an ID to the input and used that with getElementById rather than using the name (as this would return an array)
Related
I have two google spreadsheets, a master copy and a child copy. When I update the formulas in the master copy, I want it to update the formulas in the child copy too. I intend to create many copies of the child copy and don't want to update the formulas in each one every time something small has to change.
I've tried using IMPORTRANGE(), and it only gives me the values, not the formulas. So I thought to create my own script to get this done. I'm using the following code to attempt this:
function REMOTEDATA(inKey, inRange) {
var outData;
var ss = SpreadsheetApp.openById(inKey);
if (ss) {
outData = ss.getRange(inRange).getFormulas();
}
return outData;
}
//My manifest is the following:
{
"oauthScopes": [
"https://www.googleapis.com/auth/spreadsheets"
],
"timeZone": "America/Denver",
"dependencies": {
},
"exceptionLogging": "STACKDRIVER"
}
I'm very new to oAuth and I don't understand how to get this to work. When I attempt this it gives me the following:
"You do not have permission to call SpreadsheetApp.openById. Required permissions: https://www.googleapis.com/auth/spreadsheets (line 4)."
Can anyone tell me what I need to add to get this to work? If there's an easier way, I'm all ears.
EDIT:
After reading Ruben's comment below, I changed the way I was doing it to having a button on the sheet itself run the function. It fixed the first problem, but now I'm running into another problem. I can't copy all the data directly from one sheet to another. I'm trying to get formulas, values, and formatting. If I just use getFormulas() and setFormulas() with the ranges, it gets rid of all the values that aren't formulas, and it doesn't change the formatting. I've been trying to use copyTo() but it tells me I can't do this between spreadsheets. My current code is:
function REMOTEDATA() {
var MASTERKEY = "key";
var UPDATERANGES = ["A1:B200", "C7:C200", "D1:H200", "J1:L200", "N1:S200", "U1:X200", "z1:ac200", "AE1:AH200", "AJ1:AL200"];
var ss = SpreadsheetApp.openById(MASTERKEY);
var cur_ss = SpreadsheetApp.getActiveSpreadsheet();
UPDATERANGES.forEach(function(range) {
data = ss.getRange(range).copyTo(cur_ss.getRange(range));
});
}
My head is starting to hurt looking at the different methods for the Ranges Class. I can't see any methods to do this, but I feel like I'm missing something. Any other ideas?
EDIT 3:
Okay. I figured out a workaround. Basically what I did was copy the entire sheet from one spreadsheet to the other using the sheet.copyTo() function. Then after that I used the range.copyTo() to get what I wanted. Then I deleted the copied sheet using sheet.deleteSheet()
Custom functions run anonymously so they can't call services that require authorization, like openById.
Instead of using a custom function to execute your script use another method like a custom menu, assign the script to an image, etc. or just run it from the script editor.
NOTE: You will have to modify your script a bit or use a another function to pass the required arguments.
I am quite new to JS and have been given a college project where I need to use jQuery to simulate user interactions on a webform and then use qunit to validate this.
As it stands, I am attempting to set the html form fields as below using ids.
function scenario1() {
$("#price").val(1000); //sets price of textbox
$("#passengernum").val(1); //sets price of textbox
$("#myButton").click(); // clicks update button which updates a "Final price" field.
return $("#finalprice").val; // returns "Final Price" field value
}
Then in the Html, I am trying to integrate this into the qunit testing as below:
QUnit.module("ALAC Tests");
QUnit.test("", function( assert )
{
assert.equal( scenario1(),700,"TC8");
}
);
Unfortunately this causes errors on the qunit section of the html page when ran (I have this in the body).
Am I performing this test correctly or should this be done another way. The professor that has requested this assignment only gave notes on extremely basic jQuery usage.
Sorry in advance if this is a stupid question, I am very new to development.
Thanks all.
Based on my comment above, looks like you were trying to use val as a property, but it's a function. In scenario1, try doing return $("#finalprice").val() which should retrieve the value. As it stands, what you're returning is the function definition itself.
I'm making a simple math game and wanted to pass an array of questions into Pug. If the user gets a question correct, I want to update the score and display a new question. However, I wasn't sure how I could access and update the website dynamically through Pug...
Passing the values in Express:
return res.render('play', { questions: questionArray, score: 0});
Pug file:
p#question #{questions[score].num1} #{questions[score].operation} #{questions[score].num2}
p#score #{score}
input#answer
button.btn.btn-primary(onclick='checkAnswer(questions[score], score)') Enter
When I click the button to check the answer, I get the error "questions is not defined at HTMLButtonElement.onclick" in the console. I checked around on how to use onclick in Pug but it didn't seem to work. Some people suggested JSON.stringify, but it didn't seem to work.
Thanks in advance!
You can use, PUG String Interpolation, like here;
p#question #{questions[score].num1} #{questions[score].operation} #{questions[score].num2}
p#score #{score}
input#answer
button.btn.btn-primary#check-button Enter
script(type="text/javascript").
document.getElementById('check-button').addEventListener('click', function() {
let score = !{score};
let qScore = !{quesstions[score]}
// put things in "checkAnswer" function here
});
Hope this works! :)
Hey good morning/afternoon/evening depending where you guys are at!
Just have a quick question for you guys. I've been stuck on this for a bit, and I've tried looking around, but i can't seem to find the answer for this specific issue.
So I'm in the process of trying to create a column chart using google scripts with the html service (since they UIApp service is depreciated now). I'm trying to retrieve the data from a spreadsheet have already created. But when i use this code, the page comes up blank as if there is some error in the background.
var sheet = SpreadsheetApp.openById("1gdRB6FFV426bAj95C0xJlqSucnnX0Z5ATVQdC2");
So here are some specifics:
1) I put this line in my Index.html file within a function I have called
drawChart();
2) I do have them wrapped in this tag.
<script type="text/javascript">
3) I know that this line of code is the cause of the issue because as soon as i comment it out my temp graph with temp data pops up, and page runs fine. But as soon as uncommented it blanks out the whole page.
Any ideas?
I'm wondering if I have to actually place this line of code within the "Code.gs" file, then some how transfer the data from Code.gs to my Index.html file. If that's the case can anyone point me in the direction to where I can follow the direction on how to do it?
Thank you guys in advance.
Sincerely,
Sicariuxs
You must use a withSuccessHandler(functionNameToReceiveData).
<script>
function getData() {
google.script.run
.withSuccessHandler(functionNameToReceiveData)
getData();
};
function functionNameToReceiveData(theDateReceivedHere) {
Logger.log('theDateReceivedHere: ' + theDateReceivedHere;
};
</script>
You can't use: var data = google.script.run.getData(); You must use a withSuccessHandler(functionNameToReceiveData).
#Sandy Good
Hey man I want to thank you for all your help. you're answer was actually great. But there was an additional mistake on top of the ones that you corrected me on. In my actual spreadsheet I had it as a "Date" value. But the format was not matching the data type in my "dataTable". It's working now though. I made all the changes you told me, but in addition I changed the value type from "Date" to "Text". Then in my for loop I wrote a "new Date()" function using the text as the format, and that worked here is some screenshots to show my end result.
link
link
Ok, some explanation. Even though I don't think it has anything to do with the problem itself. I have a small django project that maps some data using leaflet. On a mouseover some ajax functionality is added, using the dajax(which is a "lightweight library to implement AJAX inside django projects") framework. The call itself looks like this:
dajax.add_data(simplejson.dumps(series), 'my_test_flot')
My js function receives json data which looks like this (using alert)
[{"color": "#dddd00",
"data": [[-0.5, -20.5]],
"label": "Tweede Zandlaag"}]
The object has more data to it but the problem is not with the object. When I copy/paste the data directly into the function var series = [] the behaviour is as aspected. As aspected means, the graph I'm drawing with flot is actually being drawn. Otherwise the graph remains empty.
function my_test_flot(dat) {
function MyFormatter(v, xaxis) {
return " ";
}
$(function () {
alert(dat)
var series = dat; // here lies the problem, but why?
...
Can anyone help?
Ok, problem solved. Apparently you have to use JSON.parse(). How it's done is explained here.
This does not copy the data - it just makes series a reference to the same object as dat. Therefore, if you later modify the object, all users retaining references to it see the changes. This is probably what causes your trouble.