This is my first question on stack overflow.
I need to create a path for images and path should be like this pages/assets/images/Topic02/T02P08/L1T2_P8_2a_Normal.png . So I am breaking this string into 2 parts.
1st
var dummyUrl1= "pages/assets/images/Topic02/T02P08/L1T2_P8_2";
2nd
var dummyUrl2="_Normal.png";
I just need to change 2a with 2b,2c,2d etc according to my need. So I stored these letters into an array. And picking them. And then I am making a new string string in this manner,
var currentImgUrl= dummyUrl1+arr[imageId]+dummyUrl2;
where arr=['a','b','c','d','e']
So value of currentImgUrl should be like this,
"pages/assets/images/Topic02/T02P08/L1T2_P8_2b_Normal.png" but I am getting value in this manner ,
"http://192.168.86.91/Tarun/AXON/DfMAWorking/pages/assets/images/Topic02/T02P08/L1T2_P8_2a_Normal.png"
I tried this code:
$(".clickme,.innerText").mouseenter(function(){
var arr = ['a','b','c','d','e'];
var dummyUrl1= "pages/assets/images/Topic02/T02P08/L1T2_P8_2";
var dummyUrl2="_Normal.png";
var getImageId = $(this).attr("id");
var imageId= getImageId.substring(3,4);
var currentImgUrl= dummyUrl1+arr[imageId]+dummyUrl2;
console.log("Current Image should be : "+currentImgUrl);
});
Your URL is relative, if you want http://192.168.86.91/pages/assets/...Normal.png", add a / at the beginning of dummyUrl1 dummyUrl1= "/pages/assets/images/Topic02/T02P08/L1T2_P8_2";
Related
Here's the situation:
function STP() { var LOC = window.location.href;
var CSV = LOC.substring(LOC.indexOf(',')+1);
var ARR = CSV.split(',');
var STR = ARR[ARR.length -1 ];
var POS = window.document.getElementById(STR).offsetTop;
alert( STR ); };
Explained:
When the page loads, the onload calls the script.
The script gets the location.href and Extracts the element ID by
creating an array and referencing the last one.
So far so good.
I then use that to reference an element ID to get its position.
But it doesn't work.
The STR alert indicates the proper value when it's placed above POS, not below. The script doesn't work at all below that point when the STR var reference is used.
However if I do a direct reference to the ID ('A01') no problem.
Why does one work and not the other when both values are identical? I've tried other ways like using a hash instead of a comma and can extract the value that with .location.hash, but it doesn't work either.
The problem is that when you do
LOC.substring(LOC.indexOf(',') + 1);
you're putting everything after the , into the CSV variable. But there is a space between the comma and the 'A01'. So, the interpreter reduces it to:
var POS = window.document.getElementById(' A01').offsetTop;
But your ID is 'A01', not ' A01', so the selector fails.
function STP() {
var LOC = 'file:///M:/Transfers/Main%20Desktop/Export/USI/2018/Catalog/CAT-Compilations-01a.htm?1525149288810, A01';
var CSV = LOC.substring(LOC.indexOf(',') + 1);
var ARR = CSV.split(',');
var STR = ARR[ARR.length - 1];
console.log(`'${STR}'`);
}
STP();
To solve this, you can increase the index by one:
LOC.substring(LOC.indexOf(',') + 2);
But it would probably be better not to put spaces in URLs when not necessary - if possible, send the user to 'file:///M:/Transfers/Main%20Desktop/Export/USI/2018/Catalog/CAT-Compilations-01a.htm?1525149288810,A01' instead.
I have data in a single field which is as below:
40-818-938 | COUPLING, 25MM, PVC BLACK | PCS, MTR, BUNDLE | 3
The first block is the item code, second is the item description, third are the units, they are dynamic, and fourth is the number of units. The blocks are separated by |
I want to loop through the third block (units) and put them into separate variables without commas and spaces and use them to populate a select list.
Kindly help me in achieving that. Below is the code which adds the third block into a select list according to the number of units (fourth block), I need to separate them.
for (var i = 0; i < arrData[3]; i++) {
var x = document.createElement("OPTION");
x.setAttribute("value", arrData[2]);
var t = document.createTextNode(arrData[2]);
x.appendChild(t);
input.appendChild(x);
}
Thanks in advance.
Since you've already split the original string into an array, you just need to also split the 2nd element of that array:
arrData[2] = arrData[2].split(',');
Then, inside the loop, you need to reference it like so:
x.setAttribute("value", arrData[2][i]);
var t = document.createTextNode(arrData[2][i]);
Demo
Var items = obj.split("|");
Var units = items[2].split(",");
If you want to remove the spaces as well, you can add them to the pattern to split on:
var data = '40-818-938 | COUPLING, 25MM, PVC BLACK | PCS, MTR, BUNDLE | 3';
var units = data.split(/\s*\|\s*/g)[2]; // "PCS, MTR, BUNDLE"
console.log(units.split(/\s*,\s*/)[1]); // "MTR"
and the simplest way to make an option element is to use the Option constructor:
var unit = units.split(/\s*,\s*/)[1];
var x = new Option(unit, unit);
input.appendChild(x);
You need to use split function of java script. Ex.
var newstring=string.split('|');
var laststring=newstring[2].split(",");// new string
var yourneed=laststring[1];
you can do it this way
var string1 = yourstring.split('|');
var array = string1[2] .split(',');
Build a select:
array.forEach(function(entry) {
var x = document.createElement("OPTION");
x.setAttribute("value", entry);
var t = document.createTextNode(entry);
x.appendChild(t);
input.appendChild(x);
});
Hello I'm yet again stuck on d3...
I'd like to know how to use a thousand seperator on a variable all the examples I've managed to find seem to be on static data.
This is what I've tried so far:
d3.csv("OrderValueToday.csv", function(obj) {
var text = 'Today = £';
var totalSales = text + d3.format(",") + obj[0].Today;
svgLabel = d3.select("#label").append("h2")
.text (totalSales);
});
However it just outputs a load a stuff on the webpage this is it:
Today = £function (n){var e=d;if(m&&n%1)return"";var u=0>n||0===n&&0>1/n?(n=-n,"-"):a; if(0>p){var c=Zo.formatPrefix(n,h);n=c.scale(n),e=c.symbol+d}else n*=p;n=g(n,h);var x=n.lastIndexOf("."),M=0>x?n:n.substring(0,x),_=0>x?"":t+n.substring(x+1);!s&&f&&(M=i(M));var b=v.length+M.length+_.length+(y?0:u.length),w=l>b?new Array(b=l-b+1).join(r):"";return y&&(M=i(w+M)),u+=v,n=M+_,("<"===o?u+n+w:">"===o?w+u+n:"^"===o?w.substring(0,b>>=1)+u+n+w.substring(b):u+(y?n:w+n))+e}20000
So all I want is to be able to make the totalSales value have thousand separators so like 20,000 everything else I've tried doesnt do anything. I've read this https://github.com/mbostock/d3/wiki/Formatting but didnt see what I could do for my scenario.
Any help would be greatly appreciated. Cheers
Specifying a d3.format returns a formatting function, which you must then call as a function, passing in the number to be formatted as an argument:
var myNumber = 22400;
d3.format(',')(myNumber); // returns '22,400'
Sometimes you will see a format function stored as a variable like this:
var commaFormat = d3.format(',');
commaFormat(1234567); // returns '1,234,567'
In your case, you could do the following:
var totalSales = text + d3.format(',')(obj[0].Today);
Aanval op Vlemis (499|453) C44
This is what the string looks like. Though it's actually like this: "Aanval op variable (variable) variable
What I want to do is 1: get the coordinates (I already have this), 2 get Vlemis (first variable), get C44 (third variable) and check to see if the string is of this type.
My code:
$("#commands_table tr.nowrap").each(function(){
var text = $(this).find("input[id*='editInput']").val();
var attackername= text.match(/(?=op)[\s|\w]*(?=\()/);
var coordinates = text.match(/\(\d{1,3}\|\d{1,3}\)/);
});
Coordinates works, attackername however doesn't.
Html:
<span id="labelText[6]">Aanval op Vlemis (499|453) C44</span>
You should use one regex to take everything :
var parts = text.match(/(\w+)\s*\((\d+)\|(\d+)\)\s*(\w+)/).slice(1);
This builds
["Vlemis", "499", "453", "C44"]
If you're not sure the string is valid, test like this :
var parts = text.match(/(\w+)\s*\((\d+)\|(\d+)\)\s*(\w+)/);
if (parts) {
parts = parts.slice(1);
// do things with parts
} else {
// no match, yell at the user
}
I would like to find difference between two fields using JavaScript in iText.
I am able to find the sum of them using below code:
PdfStamper stamperResult = new PdfStamper(readersectionResult, new FileOutputStream(RESULT_NEW));
stamperResult .addJavaScript("var nameField = this.getField(\"total\");"+ "nameField.setAction(\"Calculate\",'AFSimple_Calculate(\"SUM\",\"total1\", \"total2\")')");
Is there any way to find the difference using 'AFSimple_Calculate' similar to what I did in the above code snippet?
Thanks for editing! I tried your suggestion but it does not seem to work for some reason.
stamperResult.addJavaScript(" var total1 = this.getField(\"value1\"); var total2 = this.getField (\"value2\"); var subtr = this.getField(\"total\"); subtr.value = total1.value - total2.value;");
I separated newlines by spaces and added right escape characters.
I was also thinking of using a different logic for subtraction using AF methods : like this
stamperResult.addJavaScript("var nameField = this.getField(\"total\");"+ "nameField.setAction(\"Calculate\",'AFSimple_Calculate(\"SUM\",\"total1\", \"-total2\")')");
In the above code I was trying to add -(negative value) to total 2 so that it will be subtracted from total1 though the AF method is still 'SUM'.
But that does not work.
The below simple code seem to work :
stamperResult.addJavaScript("var nameField = this.getField('total');" +
"nameField.setAction('Calculate'," +
"'subtract()');" +
"" +"function subtract(){this.getField('total').value
= (this.getField('total_1').value -this.getField('total_2').value); }");
I updated your question because it contained many spelling errors. I didn't edit the code snippet because I don't know what the original code snippet is like. In any case: I think something went wrong during the copy/paste process, as I don't think your code snippet compiles in its current state.
In any case: as far as I know the AF-methods (the AF stands for Adobe Forms) may not be present in every viewer, and as far as I know Adobe didn't implement a way to subtract values from each other in the AFSimple_Calculate method.
For these two reasons, you may prefer regular JavaScript instead of using a pre-canned function that may or may not be pre-canned.
This regular JavaScript may look like this:
var total1 = this.getField("total1");
var total2 = this.getField("total2");
var subtr = this.getField("difference");
subtr.value = total1.value - total2.value;
I'm not sure if that answers your question. Maybe you just want:
var total1 = this.getField("total1");
var total2 = this.getField("total2");
var namefield = total1.value - total2.value;
You can put these lines inside a String using the right escape characters and replacing the newlines by spaces or newline characters.
Of course, you need to trigger this code somewhere. Below you'll find an example that puts the negative value of the content of a value1 field into a value2 field.
public static void main(String[] args) throws IOException, DocumentException {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("js.pdf"));
document.open();
writer.addJavaScript("function makeNegative() { this.getField('value2').value = -(this.getField('value1').value); } ");
Rectangle rect1 = new Rectangle(40, 740, 200, 756);
TextField value = new TextField(writer, rect1, "value1");
value.setBorderColor(GrayColor.GRAYBLACK);
value.setBorderWidth(0.5f);
PdfFormField field = value.getTextField();
field.setAdditionalActions(PdfName.BL, PdfAction.javaScript("makeNegative();", writer));
writer.addAnnotation(field);
Rectangle rect2 = new Rectangle(40, 710, 200, 726);
TextField neg = new TextField(writer, rect2, "value2");
neg.setBorderColor(GrayColor.GRAYBLACK);
neg.setBorderWidth(0.5f);
writer.addAnnotation(neg.getTextField());
document.close();
}
Note that I used a Blur action. This means the method will be triggered as soon as you select another field after filling out the value1 field.