jquery syntax to look for a hidden field in a form - jquery-selectors

I have a form with a table in it. In each row is a table cell with a hidden input item with the name of it starting with "hf_id_" followed by a number so that row 1's field has a name of "hf_id_1", row 2 is "hf_id_2" and so on. I need to search all of these fields for a particular value but I'm not quite sure how to get to the hidden fields. I know how to get to them when the full name is known but in this case I'm not sure if there's a way to get an array of these where name starts with "hf_id_". Thanks.

You can search elements with ^ (starting with) and $ (ending with), example:
$('input[name^="hf_id_"]');
So you can get all those elements like:
var elements = $('input[name^="hf_id_"]');
And you can iterate over them to search for a particular value like:
$('input[name^="hf_id_"]').each(function(){
if ($(this).val() === 'search value here')
{
// found..........
}
});

Or you could simply use
$('input[type="hidden"]');

Related

Flutter remove whitespace, commas, and brackets from List when going to display as a String

I want to go through my list of strings, and add it to a text element for display, but I want to remove the commas and remove the [] as well as the whitespace, but leave the symbols except the commas and brackets.
So if the List is.
[1,2,#3,*4,+5]
In the text field I want it to show - "12#3*4+5"
I can figure out how to display it, but Im using
Text(myList.tostring().replaceAll('[\\]\\,\\', '')
Is there a way to do this?
You should use the reduce method on your list.
List<String> myList = ["1", "2", "#3", "*4", "+5"];
String finalStr = myList.reduce((value, element) {
return value + element;
});
print(finalStr);
# output: "12#3*4+5"
This method reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
The method takes a function that receives two parameters: one is the current concatenated value, which starts out with the value of the first element of your list, and the second parameter is the next element on your list. So you can do something with those two values, and return it for the next iterations. At last, a single reduced value is returned. In this case, using strings, the code in my answer will concatenate the values. If those were numbers, the result would be a sum of the elements.
If you want to add anything in between elements, simply use the return value. For instance, to separate the elements by comma and whitespace, it should look like return value + " ," + element;.
Unless I'm misunderstanding the question, the most obvious solution would be to use List.join().
List<String> myList = ["1", "2", "#3", "*4", "+5"];
print( myList.join() );
// Result
// 12#3*4+5
You could also specify a separator
print( myList.join(' ') );
// Result
// 1 2 #3 *4 +5

(Matlab) How to check if cell array contains string

I am trying to grab data from an excel spread sheet and grab only the information from cells that match a string. Eg. if cell A10 contains the word 'Canada' it should return that cell.
I have tried using strcmp(https://www.mathworks.com/help/matlab/ref/strcmp.html) to check if string in argument 1 is contained in a cell array containing many strings, the second argument
[num,txt,raw] = xlsread('\\Client\C$\Users\Fish\Desktop\dataset\dataset.csv');
mytable = cell(raw);
for i = 1:54841
array_index = i;
string_index = mytable(i,2);
string_eastern = {'Canada', 'Ontario'};
if strcmp(string_index,string_eastern);
fprintf('%d\n',array_index)
end
end
In the above example if my string_eastern only contains one element, say 'Canada', it will return the index value of every instance of 'Canada'. If I add more elements I expect it would return index values for every instance where string_index would match with a string contained in string_eastern. However I get no results at all if I add more elements.
Pretty much I wanted to check my string_index agaisnt string_eastern, if the values match then I want it to return that cell value. This works when string_eastern is only 1 element but does not work with more than 1.
To access cell contents, use the curly brackets {}. So if I wanted to access the first element of my cell, I would say this:
string = cell{1};
Read more on the MATLAB Documentation about cells to learn more and to answer any of your further questions.

how an index value can be used to retrieve the respective name(string)

By using the listdlg its possible to select the file from list, but it returns the respective index as a output but not the name(string of selected entity)of the selection. how can one get the name of the selected file in output??'
for example
[Selection, ok] = listdlg(Name,Value,...);
% selection is nothing but a index of selected entities.
The dialog box is filled with a cell array provided as the value of the ListString parameter. The result of the call to listdlg is the index into this cellarray.
Consider the following code:
filelist=dir("/home");
S={filelist.name};
[Selection,ok]=listdlg('ListString',S,'SelectionMode','single');
if (ok) filename=cell2mat(S(Selection)) endif
If the selection of the item user1 was made it should output
filename = user1
Update
When SelectionMode is multiple, you could use celldisp(S(Selection)). To extract individual items use S{Selection(i)} where i ranges from 1 to length(Selection).
filelist=dir("/home");
S={filelist.name};
[Selection,ok]=listdlg('ListString',S,'SelectionMode','multiple');
if (ok)
for i=1:length(Selection)
disp(S{Selection(i)})
end
endif

How to extract value from pyspark.sql.function?

I'm using some pyspark.sql.functions:
print(ratings.select(mean('rating')).take(1))
print(ratings.select(stddev('rating')).take(1))
The output is:
[Row(avg(rating)=3.581564453029317)]
[Row(stddev_samp(rating,0,0)=1.1171018453732544)]
How can I extract the value so that I can assign it to a variable, e.g.
mean_ratings = ratings.select(mean('rating'))
Take returns a list of Rows. Index into the list to get the first row, then pull out the field you are looking for:
mean_ratings = ratings.select(mean('rating')).take(1)[0]['avg(rating)']

maskedEditColumn datagridview how to use class? is it what i need?

I am trying to mask user's input in a datagridview column and i found this ready class Masked edit column Class that adds a 'mask edit column' option in the column types list. When i select this column type a mask field is being added in the list of column properties. I tried to do my job by adding some mask elements in this 'Mask' field, but when I run the code it didnt restrict me from adding other characters. I re-opened the 'edit columns menu' and I saw that the 'Mask' field was empty.
I want the text cell to accept 20 chars maximum and only: 1.Capital Letters(English & Greek), 2.these three chars(.,-), 3.Numbers 0-9
So as a first test i used only this mask(>????????????????????) but it didnt work as it didnt convert my characters to Uppercase and accepted more than 20 chars when i end the cell edit.
i am not sure the way to go is the Masked Text Box way. i have made many projects on vb and i used to use a loop in the textChanged event of a text box to restrict characters entry. the loop is this : (but i cant use it now in the valueChanged event cause it seems that 'value' doesn't have a selectionStart property.)
Dim charactersDisallowed As String = "!##$%^&*()+=|}{][:;?/><.,~""
Dim theText As String = txtCopies.Text
Dim Letter As String
Dim SelectionIndex As Integer = txtCopies.SelectionStart
Dim Change As Integer
For x As Integer = 0 To txtCopies.Text.Length - 1
Letter = txtCopies.Text.Substring(x, 1)
If charactersDisallowed.Contains(Letter) Then
theText = theText.Replace(Letter, String.Empty)
Change = 1
End If
Next
txtCopies.Text = theText
txtCopies.Select(SelectionIndex - Change, 0)
So,
Is a masked text cell what i need? and if yes( Why is this mask box not keeping the mask i enter? And how can i use this class to do my job?)
What can i alternately do to restrict some characters in a column's cells? (I will then convert to Uppercase on cellEndEdit)
I finally did it by removing the unwanted characters on cellvaluechanged event, which seems that is being raised when I end the cell's edit by for example hitting "Enter".