input value issues in javascript - javascript

I hav a google published csv sheet. I created a html table and want to display csv values from published csv sheet into all input fields inside html table.
due to a unspecified reason this question has been moved.

You can use Split() function https://www.w3schools.com/jsref/jsref_split.asp
let splitedResult = xmlhttp.responseText.split("\r");
You can assign the values to
element.value = splitedResult[0].trim();
element1.value = splitedResult[1].trim();
Check out this link for the implementation https://jsfiddle.net/SyamKumarD/xa49vspy/29/
I would suggest you to provide a iterable id to your table elements, so you don't need to hardcode the index to your split result and you can iterate through the element and assign the split value dynamically.

Related

How does DataTables row-selector work?

I have a datatable with a number of rows:
var table = $('#mytable').DataTable(...)
And I'm trying to find the rows that contain <a>'s with specific data values.
From the documentation, I'd expect is that table.rows('<magic row-selector>') to work, for some value of <magic row-selector>. But even the simplest selectors don't seem to work the way I'd expect them to.
The docs say that if I pass a string to rows(), it is treated as a JQuery selector operating on the the <tr> elements.
http://datatables.net/reference/type/row-selector
Now I know for certain that each of these rows contains a number of 's - I can see them in the debugger if I examine the outerHTML of the elements returned by table.rows.nodes(). So I'd expect that this would return all rows:
table.rows('a')
But it returns none.
What am I not understanding?
What selector should I use, to find all of the rows that contain <a>'s with a specified value for a data attribute?
edited in response to answer
davidkonrad's answer provides some help - I need to pass a jQuery selector object, rather than a string.
Unfortunately, it seems that I need to construct the jQuery selector object before I define the table. I'm not sure I understand why, it seems an unreasonable restriction, but playing around with his fiddle, I did see differences in the rows returned by table.rows(selector) between when I defined the selector before or after I initialized the table.
In my case, then, that makes this approach unusable, because what I'm trying to do is to remove rows that have certain values set in data attributes. There is no way for me to know what values the user might have selected before I construct the table.
I also think the documentation is a little bit cryptic on that point :) The meaning is
By "jQuery selector" there is meant "the jQuery object returned by a $(selector)"
Only jQuery objects containing <tr>'s is allowed
On paginated tables, you must create the "jQuery selector" before instantiating the dataTable
So, if you want to pass a jQuery object to a dataTables API instance, that contains all rows where any <td> contains the text "test"
var selector = $('tr:contains("test")');
var table = $('#example').DataTable();
var rows = table.rows(selector).data();
//now you can iterate
for (var i=0;i<rows.length;i++) {
//each rows[i] is an array of the rows columns
console.dir(rows[i]);
}
if you want to pass a jQuery object to a dataTables API instance, that contains all rows where any <td> contains an <a> containing a certain text, like "test"
var selector = $('tr a:contains("test")').parent().parent();
...
var rows = table.rows(selector).data();
...
the above selectors in an example -> http://jsfiddle.net/q2p2n23m/

Copy values of multiple cells on form submit into a single cell in a different Google Sheet

I'm trying to grab multiple cells from the last row of a Google Sheet upon a form submittal and copy them to a single cell in different sheet.
How do I combine the values in this array into one value? I'd like to put a comma and space between the data.
var daterange = sourcesheet.getRange("H"+source_last_row+":Q"+source_last_row);
I'm not even sure the query is correct. The Logger says "Range". :\
I am grabbing the values below this in the script.
var source_range6_values = daterange.getValues();
Logger returns "Range" because your variable is just a range. To get an array of the values in that range, you need to use the .getValues() method.
var daterange = sourcesheet.getRange("H"+source_last_row+":Q"+source_last_row);
var daterangeVals = daterange.getValues();
You can then use the .toString() method to convert the array to string.
That will return the values separated by a comma. As you want a comma and a space, you could then use the .replace() method on the string.

Titanium- JavaScript : How to set check mark of a particular row if the values of row existed in a selected array

I was very new to titanium and java script
I have populated a table view with an array myArray
as follows
$.table.setData(myArray);
in that myArray contains JSon formatted values like (title:value1, title:value2)
And i have an another array 'selectedArray' of selected values
Now i need to check each row values that it was existed in 'selectedArray' or not
if it was already existed in 'selectedArray' then we need to disply a check marK
how to achieve this can any one help me
There are 2 basic ways:
You can maintain single array and add a field named selected (true/false)
While adding the elements to myArray you can check for same element in selectedArray and add checkmark accordingly

how to access json data attribute

I have a data-attribute for several element that I'm using to store an ID and a value for each picklist values for each element. These will all be used to populate one field in a modal if one of the elements is edited.
I've added the ID and name for each option for each element into the data attribute like so:
{id:a0Dd000000RT1dOEAT,name:aa},{id:a0Dd000000RT1dPEAT,name:bb}, {id:a0Dd000000RT1dQEAT,name:cc},{id:a0Dd000000RT1dREAT,name:dd},{id:a0Dd000000RT1dSEAT,name:ee}
These represents 5 picklist options for one of the elements.
What is the syntax to extract each one? I've tried versions of:
$('#elementID').data('picklistvalues')[0].id
and its not working, any suggestions? I'm obviously far from a javascript expert.
You need to JSON.parse() the value that .data() returns; then you can work with the value as a full JavaScript object.
var data = $('#elementID').data('picklistvalues');
// the attr value in the OP is not quite valid JSON
var obj = JSON.parse('[' + data + ']');
var id = obj[0].id;
It looks to me that you need to place quotes around the "id" values. These are not quite numbers and will not likely parse as anything but strings.

Coping data in number of rows

<script>
function copy_data(val){
var a = document.getElementById(val.id).value
document.getElementById("copy_to").value=a
}
</script>
i am using this code in head portion for copying data from one text box to another. I need to know what can i do to copy data in number of fields in different rows to copy data from one column to another of the same row?
You can choose among popular javascript libraries and use their css based selectors to query your fields. A couple of examples:
JQuery's $: http://api.jquery.com/category/selectors/
dojo.query: http://dojotoolkit.org/reference-guide/dojo/query.html
As a result of the query you obtain an array like object (depending of the library) which gives you the ability to iterate over, and do your copying.

Categories

Resources