document.createTextNode not working :/ - document

So i am making this program where i need to create an ordered list with lots of list elements inside. This is the code:
for(i = 0; i < numbers.length; i++) {
document.createElement("ls").appendChild(document.createTextNode(eval(numbers[i])));
document.getElementById("list").appendChild(document.createElement("ls"));
}
It only creates the list elements, it doesn't put the text nodes anywhere in the html document. :/
Does anyone know why this happens and how to fix it? Would really help me out.

Instead of adding the "ls" element you've created on the first row to the "list" element, you're creating a new (empty) one and adding it.
Change it to:
var ls = document.createElement("ls").appendChild(document.createTextNode(eval(numbers[i])));
document.getElementById("list").appendChild(ls);

Related

Using composed xpath to locate an element and click on it

I am trying to retrieve a list of elements using XPATH and from this list I want to retrieve a child element based on classname and click it.
var rowList = XPATH1 + className;
var titleList = className + innerHTMLofChildElement;
for(var i = 0; i < titleList.length; i++) {
if(titleList[i][0] === title) {
browser.click(titleList[i][0]); //I don't know what to do inside the click function
}
}
I had a similar implementation perhaps to what you are trying to do, however my implementation is perhaps more complex due to using CSS selectors rather than XPath. I'm certain this is not optimized, and can most likely be improved upon.
This uses the methods elementIdText() and elementIdClick() from WebdriverIO to work with the "Text Values" of the Web JSON Elements and then click the intended Element after matching what you're looking for.
http://webdriver.io/api/protocol/elementIdText.html
http://webdriver.io/api/protocol/elementIdClick.html
Step 1 - Find all your potential elements you want to work with:
// Elements Query to return Elements matching Selector (titles) as JSON Web Elements.
// Also `browser.elements('<selector>')`
titles = browser.$$('<XPath or CSS selector>')
Step 2 - Cycle through the Elements stripping out the InnerHTML or Text Values and pushing it into a separate Array:
// Create an Array of Titles
var titlesTextArray = [];
titles.forEach(function(elem) {
// Push all found element's Text values (titles) to the titlesTextArray
titlesTextArray.push(browser.elementIdText(elem.value.ELEMENT))
})
Step 3 - Cycle through the Array of Title Texts Values to find what you're looking for. Use elementIdClick() function to click your desired value:
//Loop through the titleTexts array looking for matching text to the desired title.
for (var i = 0; i < titleTextsArray.length; i++) {
if (titleTextsArray[i].value === title) {
// Found a match - Click the corresponding element that
// it belongs to that was found above in the Titles
browser.elementIdClick(titles[i].value.ELEMENT)
}
}
I wrapped all of this into a function in which i provided the intended Text (in your case a particular title) I wanted to search for. Hope this helps!
I don't know node.js, but in Java you should achieve your goal by:
titleList[i].findElementBy(By.className("classToFind"))
assuming titleList[i] is an element on list you want to get child elements from

Wildcard for hitTestObject ActionScript3 show Instance Name

I have movieClips namely rec1, rec2, rec3, rec4...
Then, I would addChild another movieclip(circle_mc) to those rec MovieClips.
I want to use the hitTestObject... Something like this:
circle_mc.hitTestObject(this["rec" + numStringTarget])
If I specify number on the numStringTarget variable, I can only attach to one of the "rec" movieclips. What I want is the capability of circle_mc to be added on any "rec" movieclips. Is there any way to use wildcard? Or any way to solve it?
I want the code to become like this:
circle_mc.hitTestObject(contains String "rec") then addChild..
I hope someone can solve it or just give me some helpful links to read about. Thanks in advance.
I do not want to set all these statements this way:
circle_mc.hitTestObject(rec1);
circle_mc.hitTestObject(rec2);
circle_mc.hitTestObject(rec3);
circle_mc.hitTestObject(rec4);
what if I have a hundreds or thousands... I want to test if the movieclip, as long as it has word "rec" on its instance name, it will be tested.
Or it could be in another situation. My circle_mc is draggable. Then when it hit another movieclip on stage, is there any way to show up the instance name hit by the circle_mc?
for (var i:int = 0; i < _totalRecObjects; ++i) {
circle_mc.hitTestObject(this["rec" + i]);
}

How to get number of options in Combo Box in SSJS?

I've tried getComponent("ComboBoxID").getChildCount() but that appears to not return the correct number. Anyone know if there is a method I can use? Or maybe a function needs to be created?
EDIT - And is there a way to loop through the options and get the values like in CSJS?:
for (var i = 1; i < comboBox.options.length; i++){
pmtPlan = comboBox.options[i].value;
...
Maybe this XSnippet can help:
http://openntf.org/XSnippets.nsf/snippet.xsp?id=get-selectable-values-of-a-component
Instead of printing the selectable value(s) you have to count them.
Hope this helps
Sven

MFC displaying multiple-lines of text in Edit Control box

I am trying to implement a tool that displays file names.
I would like to do this by using SetWindowText() method.
However, When I was trying to use this method in a loop,
the text is displayed in one line and it is continuously refreshed.
here is code snippet
for (int i = 0; i<10; i++)
{
SetWindowText(filenames);
}
please help.! thanks.
SetWindowText replaces the current window text with the string you provide.
So, if you want to show multiple lines with it, you first have to create a multi-line string.
A quick example:
CStringArray names;
// Fill names
CString str;
for (INT_PTR i = 0; i < names.GetCount() ; ++i)
{
str += names[i] + _T("\r\n");
}
c_MyEdit.SetWindowText(str);
Another time-tested method of showing multiple names at once is the list box. MFC provides a nice wrapper with the CListBox Class (see http://msdn.microsoft.com/en-us/library/y04ez4c9%28v=vs.80%29.aspx). This has the added benefit of being scrollable and (optionally) sortable if the list is long.

SharePoint List Item Not Returning Fields

Hi I have a question about SPListItem and how to retrieve values from it. In the view I am in I can access the "Article" no problem but when I try to access the "Link" I can an error saying object not initalized. I don't understand whats going on? Why can I not get the Link when I can get the Article field. Here is the code I am using:
SPList myList = eachWeb.Lists["Listings"];
SPListItemCollection myItemCollection = myList.GetItems(myList.Views["Active Announcements"]);
for (int i = 0; i < myItemCollection.Count; i++)
{
SPListItem realitem = myItemCollection[i];
writer.Write(realitem["Article"].ToString()+"<BR>"); // Works without the bottom line
writer.Write(realitem["Link"].ToString()+"<BR>"); // Causes error
My view contains a column for both Article and Link. Thank you.
The internal name of a field may not match the display name; especially if you've changed the name after creating the list. Try debugging and taking a look at the names of the fields in the SPListItemCollection and see if you can figure out which one it is there.

Resources