How to Get Seleted Value from each on dropdown list - each

I want to change every drop-down list into span with the text that is selected.
How shall I do this?
My Code:
$.each($("#ShowFormResult select"), function (i, val)
{
$(this).replaceWith("<span>" + $(this + " option:selected").text() + "</span>");
});

$.each ($ ("#ShowFormResult select"), function (i, val)
{
$(this).replaceWith("" + $(this + " option:selected").text() + "");
});

Related

Function doesn't execute inside loop

I'm making a simple terminal calculator but for some reason a function isn't executing inside a while loop but executes outside the loop.
Given this input: ((1 + 2) + (3 + 4))
It should output:10
But gets stuck in an infinite loop because it doesn't replace the innermost expressions with their result.
The function that doesn't execute is s.replace(basicOp, answer);
Here is a snippet of the problem:
public static function processInput(s:String):String
{
var result:Null<Float> = parseNumber(s);
if (result != null)
{
return Std.string(result);
}
var closeParPos:Int = 0;
var openParPos:Int = 0;
var basicOp:String;
var answer:String = "";
// ERROR HERE
while (Std.string(answer) != s)
{
closeParPos = s.indexOf(")");
openParPos = s.lastIndexOf("(", closeParPos);
basicOp = s.substring(openParPos, closeParPos + 1);
answer = processBasicOp(basicOp);
// This isn't executed
s.replace(basicOp, answer);
trace("Input: " + s + " basicOp: " + basicOp + " Answer: " + answer);
}
return (result == null)? "": Std.string(result);
}
All the code is here just run make test
The input syntax is: ([number] [operator] [number]) or ([operator] [number])
There must be a single space between number and operators.
There shouldn't be any space between numbers and parenthesis
Supported operations:
+ - / *
% (remainder),
div (quotient),
sqr (square),
sqroot (square root),
sin cos tan (in degrees, bugged)
fact (factorial)
It isn't completed yet, there may be other problems, but this problem prevents me from advancing.
Can someone help me find the solution?
Thank you.
I can't actually get this to run, but StringTools.replace() doesn't modify the string in-place.
Try changing s.replace(basicOp, answer); to s = s.replace(basicOp, answer);

Swift - Update UITextView with string using IBAction without deleting old string

I am trying to send and update strings inside a UITextView using and IBAction button.
the code below works fine however, every time i push the button the old text is replaced with the new one. What I am trying to do is to always append the text to the exiting one.
Any Idea?
#IBAction func equalPressed(sender: AnyObject) {
var resultString:String = "new string"
textView.text = resultString.stringByAppendingString("= " + resultLabel.text! + ";")
}
You already know how to append strings, but you're doing it two different ways. The stringByAppendingString(_:) method is fine, but Swift's + operator is clearer. I'd rewrite your existing method as follows:
#IBAction func equalPressed(sender: AnyObject) {
let resultString = "new string"
textView.text = resultString + "= " + resultLabel.text! + ";"
}
Then, to append the text rather than replace it, it's a simple change of including the old value in the new one:
textView.text = textView.text + resultString + "= " + resultLabel.text! + ";"
Or, using the += operator (x += y is short for x = x + y):
textView.text += resultString + "= " + resultLabel.text! + ";"

Adding multiple shapes in d3

I would like to add different shapes depending on one of the properties in my json file. I found this approach by Mike:
https://groups.google.com/forum/#!topic/d3-js/4EJDu1xOh8Y
The idea is great, I'm just not sure how to adapt it. I either want to add a circle or an svg:use element (with attr("xlink:href")). They both have (of course) different attributes. So how do I do that? What do I append? In the example, the attr("d") was also used, do I need that also?
That's what I have so far but I'm not sure what to add where.
I really appreciate your help!
var type = d3.scale.ordinal()
.domain(["Q", "C"])
.range("circle","svg:use");
for(l=0;l<4;l++){
currentsvg.selectAll("path")
.data(queryArray[l])
.enter()
.append("svg:path")
.type(function(d,i) {
if (queryArray[l][i].name.substr(0,1) == "Q"){
return type("Q");
}
else if (queryArray[l][i].name.substr(0,1) == "C"){
return type("C");
}
});
}
Below is a different solution without filtering that uses the path to draw the shapes. It doesn't use the "rect" or "circle" of svg but rather just uses the path to draw the shapes. Check out here for more on paths. Note that the circle is two connecting arcs. It also classes each shape based on the data so you can have different colors, etc using CSS. Here is a fiddle.
currentsvg.selectAll("path")
.data(data)
.enter()
.append("path")
.attr("d",function(d,i){
var path,
s = i*50,
r = 10,
w = r*2;
if (data[i] == "Q"){
path = "M" + s + " " + s + " L" + s + " " + (s+w) +
" L" + (s+w) + " " + (s+w) + " L" + (s+w) + " " + s + "Z"
}
else if (data[i] == "C"){
path = "M" + s + " " + s + " m" + -r + ", 0 " +
" a " + r + "," + r + " 0 1,0 " + r*2 + ",0" +
" a " + r + "," + r + " 0 1,0 "+ -r*2 + ",0"
}
return path;
})
.attr("class", function(d){return d == "Q" ? "rec" : "circ";})
The best way to do that is to filter the data how you want into separate data sets for each shape before you create shapes. Then you can create the shapes with that new data set.
var data = ["Q","Q","Q","C","C","Q","Q","C","Q","C"];
var circleSet = data.filter(function(d){return d === "Q";}),
squareSet = data.filter(function(d){return d === "C";});
As Lars said, that is also not how the d attribute works. Here is a working JSFiddle of the whole thing.

Reading style names in table cell of doc file in Apache-POI

I am able to read the table cells, But I wanted also to read the applied style name of each cell of a row in a table. How can I achieve this?
EDIT
Following is the code snip which I have tried. By this I am able to read cell text also the applied pstyle(para style), but not able to read the rstyles.
private static void processDoc(String path) throws Exception {
POIFSFileSystem fis = new POIFSFileSystem(new FileInputStream(path));
HWPFDocument wdDoc = new HWPFDocument(fis);
// list all style names and indexes in stylesheet
/*for (int j = 0; j < wdDoc.getStyleSheet().numStyles(); j++) {
if (wdDoc.getStyleSheet().getStyleDescription(j) != null) {
System.out.println(j + ": " + wdDoc.getStyleSheet().getStyleDescription(j).getName());
} else {
// getStyleDescription returned null
System.out.println(j + ": " + null);
}
}*/
// set range for entire document
Range range = wdDoc.getRange();
for (int i = 0; i < range.numParagraphs(); i++) {
Paragraph p = range.getParagraph(i);
// check if style index is greater than total number of styles
if (wdDoc.getStyleSheet().numStyles() > p.getStyleIndex()) {
//System.out.println(wdDoc.getStyleSheet().numStyles() + " -> " + p.getStyleIndex());
StyleDescription style = wdDoc.getStyleSheet().getStyleDescription(p.getStyleIndex());
String styleName = style.getName();
// write style name and associated text
System.out.println(styleName + " -> " + p.text().replaceAll("[\u0000-\u001f]", ""));
} else {
System.out.println("\n" + wdDoc.getStyleSheet().numStyles() + " ----> " + p.getStyleIndex());
}
}
}

How to go to next line while using a loop to setText in JTextArea?

This is my code
for (int m=0; m < i ; m++){
ta1.setText( s[m].getName().toString() + ", " + s[m].getProgramName().toString() + ", " + s[m].getUni1() + ", " + s[m].getUni2() + ", " + s[m].getUni3() + ", " );
}
It's supposed to print a line from an array of student ( called s) into a JTextArea ( called ta1 ). the problem is that it always only prints the last student in the array.
I need to print each student in a new line. could anyone help me sort it out?
When you set text on an element, the current position in the loop will take over the last one.
Try doing this.
String s = "";
for(int m = 0, m <i; m++){
s += s[m].getName.toString() + ", " + s[m].getprogramName().toString() + "\n;
}
ta1.setText(s);
Create a string and add each entry to it then add new line to end of each entry "\n"
Then do.
ta1.setText(s);
setText overwrites whatever is the current text.
You need append instead; you also need a "\n" at the end of a line.

Resources