Photoshop script is not working correctly - javascript

This script changes the color of the text in the active layer to black, exports it as a PNG file with the specified name, then it changes the color of the text in the active layer to white, and exports it again as a PNG file with the specified name, and it repeats the same process with different colors (pink, blue, green, red) and save them as PNG files with different names.
The Black, Blue, Green and Red are exported correctly. However white (which comes right after black) is exported as light blue and the pink file (which comes after white) is exported as the same color of the blue file.
var textColor = new SolidColor();
textColor.rgb.hexValue = “000000”;
app.activeDocument.activeLayer.textItem.color = textColor;
var textLayerName = app.activeDocument.activeLayer.name;
var newName = prompt(“Enter a new name for the export”, “black_” + textLayerName);
var exportOptions = new ExportOptionsSaveForWeb();
exportOptions.format = SaveDocumentType.PNG;
exportOptions.quality = 100;
var file = new File("black " + newName + “.png”);
app.activeDocument.exportDocument(file, ExportType.SAVEFORWEB, exportOptions);
var textColor = new SolidColor();
textColor.rgb.hexValue = “FFFFFF”;
app.activeDocument.activeLayer.textItem.color = textColor;
var file2 = new File("white " + newName + “.png”);
app.activeDocument.exportDocument(file2, ExportType.SAVEFORWEB, exportOptions);
var textColor = new SolidColor();
textColor.rgb.hexValue = “fc82d8”;
app.activeDocument.activeLayer.textItem.color = textColor;
var file3 = new File("pink " + newName + “.png”);
app.activeDocument.exportDocument(file3, ExportType.SAVEFORWEB, exportOptions);
var textColor = new SolidColor();
textColor.rgb.hexValue = “63a8e7”;
app.activeDocument.activeLayer.textItem.color = textColor;
var file4 = new File("blue " + newName + “.png”);
app.activeDocument.exportDocument(file4, ExportType.SAVEFORWEB, exportOptions);
var textColor = new SolidColor();
textColor.rgb.hexValue = “0c6a27”;
app.activeDocument.activeLayer.textItem.color = textColor;
var file5 = new File("green " + newName + “.png”);
app.activeDocument.exportDocument(file5, ExportType.SAVEFORWEB, exportOptions);
var textColor = new SolidColor();
textColor.rgb.hexValue = " a80000";
app.activeDocument.activeLayer.textItem.color = textColor;
var file6 = new File("red " + newName + “.png”);
app.activeDocument.exportDocument(file6, ExportType.SAVEFORWEB, exportOptions);

Related

Text color not changing correctly during export in Adobe Photoshop script

I am trying to create a script that changes the color of the text in the active layer to black, exports it as a PNG file with the specified name, then changes the color of the text to white and exports it again as a PNG file with the specified name, and repeats the same process with different colors (pink, blue, green, red) and saves them as PNG files with different names. The script is exporting the files correctly, but all of the files are being exported as black and not in the respective colors. I have tried adding =null before recoloring but the activeLayer cannot be equal to null or undefined. Can someone please help me figure out why my script is not working as intended and how I can fix it?
Here is the code:
app.activeDocument.activeLayer.textItem.color = new SolidColor();
app.activeDocument.activeLayer.textItem.color.rgb.hexValue = "000000";
var textLayerName = app.activeDocument.activeLayer.name;
var newName = prompt("Enter a new name for the export", "black_" + textLayerName);
var exportOptions = new ExportOptionsSaveForWeb();
exportOptions.format = SaveDocumentType.PNG;
exportOptions.quality = 100;
var file = new File("black " + newName + ".png");
app.activeDocument.exportDocument(file, ExportType.SAVEFORWEB, exportOptions);
app.activeDocument.activeLayer.textItem.color = new SolidColor();
app.activeDocument.activeLayer.textItem.color.rgb.hexValue = "FFFFFF";
var file2 = new File("white " + newName + ".png");
app.activeDocument.exportDocument(file2, ExportType.SAVEFORWEB, exportOptions);
app.activeDocument.activeLayer.textItem.color = new SolidColor();
app.activeDocument.activeLayer.textItem.color.rgb.hexValue = "fc82d8";
var file3 = new File("pink " + newName + ".png");
app.activeDocument.exportDocument(file3, ExportType.SAVEFORWEB, exportOptions);
app.activeDocument.activeLayer.textItem.color = new SolidColor();
app.activeDocument.activeLayer.textItem.color.rgb.hexValue = "63a8e7";
var file4 = new File("blue " + newName + ".png");
app.activeDocument.exportDocument(file4, ExportType.SAVEFORWEB, exportOptions);
app.activeDocument.activeLayer.textItem.color = new SolidColor();
app.activeDocument.activeLayer.textItem.color.rgb.hexValue = "0c6a27";
var file5 = new File("green " + newName + ".png");
app.activeDocument.exportDocument(file5, ExportType.SAVEFORWEB, exportOptions);
app.activeDocument.activeLayer.textItem.color = new SolidColor();
app.activeDocument.activeLayer.textItem.color.rgb.hexValue = "a80000";
var file6 = new File("red " + newName + ".png");
app.activeDocument.exportDocument(file6, ExportType.SAVEFORWEB, exportOptions);```
I may be wrong, but I don't think you can declare a text color as a new solid colour directly
You have to do it in this format:
var textColor = new SolidColor();
textColor.rgb.hexValue = "fc82d8";
app.activeDocument.activeLayer.textItem.color = textColor;
It also helps if you declare a variable as the active document
var srcDoc = app.activeDocument;
Saves you typing out "app.activeDocument" each time :)
I think you've got your colours mixed up - the last one listed is a red colour but given the name "green".
As you're doing a repetitive task, it's easier to do it in a loop:
// Switch off any dialog boxes
displayDialogs = DialogModes.ERROR; // OFF
var srcDoc = app.activeDocument;
var textLayerName = srcDoc.activeLayer.name;
var newName = prompt("Enter a new name for the export", "black_" + textLayerName);
var exportOptions = new ExportOptionsSaveForWeb();
exportOptions.format = SaveDocumentType.PNG;
exportOptions.quality = 100;
var colours = [
["000000", "black" ],
["FFFFFF", "white" ],
["FC82D8", "pink"],
["63A8E7", "blue"],
["007236", "green"], // change this colour
["A80000", "red"],
]
var textColor = new SolidColor();
for (var i = 0; i < colours.length; i++)
{
var col = colours[i][1];
textColor.rgb.hexValue = colours[i][0];
app.activeDocument.activeLayer.textItem.color = textColor
// a space is added to the filename here
var file = new File(col + newName + " .png");
srcDoc.exportDocument(file, ExportType.SAVEFORWEB, exportOptions);
}

Safari downloads vcf as example.com javascript

I am trying to generate a vCard .vcf file and download it on click. It works perfectly for all browsers except Safari. On safari, it downloads example.com instead of the proper file. I read a lot about the Safari download attribute issue, but it seems this is not the problem in my case. Any help would be highly appreciated.
This is my crappy code :)
let vCard = document.querySelector('.vcard')
let vcard_start ="BEGIN:VCARD\nVERSION:3.0\n"
let vcard_end = "END:VCARD"
let fullName = document.querySelector('#fullname').innerText
//let firstName = document.querySelector('#firstname').innerText
//let lastName = document.querySelector('#lastname').innerText
let title = document.querySelector('#title').innerText
let email = document.querySelector('#email').innerText
let phone = document.querySelector('#phone').innerText
let address = document.querySelector('#address').innerText
let vcard_download = document.querySelector('#vcard-download')
let currentURL = window.location.href
let attPhoto = document.querySelector('#att_image')
let attPhotoSRC = attPhoto.querySelector('img').src
let splitName = fullName.split(' ')
//let vCardPhoto =
//const space = split(/\r?\n/);
let vcardReady
let newName
if(splitName.length>=3){
newName = splitName[2] + ';' + splitName[0] + ' ' + splitName[1]
}else{
newName = splitName[1] + ';' + splitName[0]
}
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href','data:text/vcard;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
let base64_image_encoded;
window.addEventListener('load',function(){
// Start file download.
vcard_download.addEventListener("click", function(){
const tmp = base64_image_encoded.split(",");
// Generate download of vCard file with some content
vcardReady = vcard_start+
"FN:"+fullName+ "\n" +
"N:" + newName + "\n" +
"EMAIL:" + email + "\n" +
"ORG:Carella, Byrne, Cecchi, Brody & Agnello, P.C\n" +
"ROLE:" + title + "\n" +
"TEL;TYPE=WORK;VOICE:" + phone + "\n" +
"URL:" + currentURL + "\n" +
"PHOTO;TYPE=JPEG;ENCODING=BASE64:"+ tmp[1] + "\n" +
"NOTE;CHARSET=us-ascii;ENCODING=QUOTED-PRINTABLE:" + "\n" +
vcard_end;
var text = vcardReady;
var filename = fullName+'.vcf';
download(filename, text);
});
toDataURL(attPhotoSRC, function (dataUrl) {
base64_image_encoded = dataUrl;
});
});
function toDataURL(src, callback, outputFormat) {
let image = new Image();
image.crossOrigin = 'Anonymous';
image.onload = function () {
let canvas = document.createElement('canvas');
let ctx = canvas.getContext('2d');
let dataURL;
canvas.height = this.naturalHeight;
canvas.width = this.naturalWidth;
ctx.drawImage(this, 0, 0);
dataURL = canvas.toDataURL(outputFormat);
callback(dataURL);
};
image.src = src;
if (image.complete || image.complete === undefined) {
image.src = "data:image/gif;base64, R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
image.src = src;
}
return image;
}
I have seen this issue when there was a newline character in the filename for Safari. Removing that newline did the trick for me

Change an element's value from servlet and return data to webpage without refresh with ajax

I have a web page and a servlet. I create input elements dynamically with using javascript in webpage. The servlet is back-end that evaluate some mathematical calculations. I am getting the data to send to servlet from dynamically created input elements. These input elements id's are also been creating dynamically. I am able to retrieve data and create the elements without any error.
But, I want to evaluate some mathematical operations in servlet then send to result to an 'result' textbox in the webpage. So I don't want to refresh the web page. Beacause the 'result' id textbox is also been creating dynamically.
The related html code.
<form action="/TYT_Mat_Soru_Cozumu_Java_war_exploded/Servlet/HesaplamaIslemleri" method="post" id="sayilarForm">
<input type="hidden" name="grupNoTutan" id="grupNoTutan"></input>
</form>
The code that dynamically create input elements.
function sayiEklemeKutular(operatorTipi){
var satir_1Div = document.createElement("div");
satir_1Div.setAttribute("class", "row");
satir_1Div.setAttribute("id", grup_no + "_satir_1");
var satir_2Div = document.createElement("div");
satir_2Div.setAttribute("class", "row");
var satir_3Div = document.createElement("div");
satir_3Div.setAttribute("class", "row");
var satir_4Div = document.createElement("div");
satir_4Div.setAttribute("class", "row");
var satir_5Div = document.createElement("div");
satir_5Div.setAttribute("class", "row");
var node = "";
switch (operatorTipi) {
case "+":
node = document.createTextNode('+');
break;
case "-":
node = document.createTextNode('-');
break;
case "*":
node = document.createTextNode('*');
break;
case "/":
node = document.createTextNode('/');
break;
case "√":
node = document.createTextNode('√');
break;
case "0/":
node = document.createTextNode('0/');
break;
case "^√==":
node = document.createTextNode('^√==');
break;
case "^==":
node = document.createTextNode('^==');
break;
default:
node = document.createTextNode('Hata');
}
satir_3Div.appendChild(node);
satir_3Div.style.textAlign = "center";
satir_3Div.style.fontSize = "14pt";
satir_3Div.style.fontColor = "#ffffff";
var satir_2_sutun_1Div = document.createElement("div");
var satir_2_sutun_2Div = document.createElement("div");
var satir_2_sutun_3Div = document.createElement("div");
satir_2_sutun_1Div.setAttribute("class", "col");
satir_2_sutun_2Div.setAttribute("class", "col");
satir_2_sutun_3Div.setAttribute("class", "col");
var satir_4_sutun_1Div = document.createElement("div");
var satir_4_sutun_2Div = document.createElement("div");
var satir_4_sutun_3Div = document.createElement("div");
satir_4_sutun_1Div.setAttribute("class", "col");
satir_4_sutun_2Div.setAttribute("class", "col");
satir_4_sutun_3Div.setAttribute("class", "col");
var satir_5_sutun_1Div = document.createElement("div");
var satir_5_sutun_2Div = document.createElement("div");
var satir_5_sutun_3Div = document.createElement("div");
satir_5_sutun_1Div.setAttribute("class", "col");
satir_5_sutun_2Div.setAttribute("class", "col");
satir_5_sutun_3Div.setAttribute("class", "col");
var kokDerece1 = document.createElement("input");
var kokKatsayi1 = document.createElement("input");
var kokIciDeger1 = document.createElement("input");
kokDerece1.setAttribute("name", grup_no + "_kokDerecesi_" + komponent_no);
kokDerece1.setAttribute("id", grup_no + "_kokDerecesi_" + komponent_no);
kokDerece1.setAttribute("class", "form-control");
kokDerece1.setAttribute("type", "text");
kokDerece1.setAttribute("placeholder", "Kökün Derecesi");
kokIciDeger1.setAttribute("name", grup_no + "_kokIciDeger_" + komponent_no);
kokIciDeger1.setAttribute("id", grup_no + "_kokIciDeger_" + komponent_no);
kokIciDeger1.setAttribute("class", "form-control");
kokIciDeger1.setAttribute("type", "text");
kokIciDeger1.setAttribute("placeholder", "Kök İçindeki Değer");
kokKatsayi1.setAttribute("name", grup_no + "_kokKatsayi_" + komponent_no);
kokKatsayi1.setAttribute("id", grup_no + "_kokKatsayi_"+ komponent_no);
kokKatsayi1.setAttribute("class", "form-control");
kokKatsayi1.setAttribute("type", "text");
kokKatsayi1.setAttribute("placeholder", "Kökün Katsayısı");
komponent_no = komponent_no + 1;
var kokDerece2 = document.createElement("input");
var kokIciDeger2 = document.createElement("input");
var kokKatsayi2 = document.createElement("input");
kokDerece2.setAttribute("name", grup_no + "_kokDerecesi_" + komponent_no);
kokDerece2.setAttribute("type","text");
kokDerece2.setAttribute("id", grup_no + "_kokDerecesi_" + komponent_no);
kokDerece2.setAttribute("class", "form-control");
kokDerece2.setAttribute("placeholder", "Kökün Derecesi");
kokIciDeger2.setAttribute("name", grup_no + "_kokIciDeger_" + komponent_no);
kokIciDeger2.setAttribute("type", "text");
kokIciDeger2.setAttribute("id", grup_no + "_kokIciDeger_" + komponent_no);
kokIciDeger2.setAttribute("class", "form-control");
kokIciDeger2.setAttribute("placeholder", "Kök İçindeki Değer");
kokKatsayi2.setAttribute("name", grup_no + "_kokKatsayi_" + komponent_no);
kokKatsayi2.setAttribute("type","text");
kokKatsayi2.setAttribute("id", grup_no + "_kokKatsayi_"+ komponent_no);
kokKatsayi2.setAttribute("class", "form-control");
kokKatsayi2.setAttribute("placeholder", "Kökün Katsayısı");
var sonucInput = document.createElement("INPUT");
sonucInput.setAttribute("class", "form-control");
sonucInput.setAttribute("name", grup_no + "_sonuc");
sonucInput.setAttribute("id", grup_no + "_sonuc");
sonucInput.setAttribute("placeholder", "Sonuç");
var silButon = document.createElement("BUTTON");
silButon.setAttribute("class", "btn btn-danger");
silButon.setAttribute("name", grup_no + "_silButon");
silButon.textContent = "Grubu Sil";
silButon.setAttribute("onclick", 'silButonununGrupNosunuGetir(this.getAttribute("name"))');
var hesaplaButon = document.createElement("BUTTON");
hesaplaButon.setAttribute("class", "btn btn-success");
hesaplaButon.setAttribute("type", "submit");
hesaplaButon.setAttribute("name", grup_no + "_hesaplaButon");
hesaplaButon.setAttribute("onclick", 'ismiHiddenaEkle(this.getAttribute("name"))');
hesaplaButon.textContent = "Hesapla";
komponent_no = 1;
grup_no = grup_no + 1;
satir_2_sutun_1Div.appendChild(kokDerece1);
satir_2_sutun_2Div.appendChild(kokKatsayi1);
satir_2_sutun_3Div.appendChild(kokIciDeger1);
satir_2Div.appendChild(satir_2_sutun_1Div);
satir_2Div.appendChild(satir_2_sutun_2Div);
satir_2Div.appendChild(satir_2_sutun_3Div);
satir_4_sutun_1Div.appendChild(kokDerece2);
satir_4_sutun_2Div.appendChild(kokKatsayi2);
satir_4_sutun_3Div.appendChild(kokIciDeger2);
satir_4Div.appendChild(satir_4_sutun_1Div);
satir_4Div.appendChild(satir_4_sutun_2Div);
satir_4Div.appendChild(satir_4_sutun_3Div);
satir_5_sutun_1Div.appendChild(sonucInput);
satir_5_sutun_2Div.appendChild(silButon);
satir_5_sutun_3Div.appendChild(hesaplaButon);
satir_5Div.appendChild(satir_5_sutun_1Div);
satir_5Div.appendChild(satir_5_sutun_2Div);
satir_5Div.appendChild(satir_5_sutun_3Div);
satir_1Div.appendChild(satir_2Div);
satir_1Div.appendChild(satir_3Div);
satir_1Div.appendChild(satir_4Div);
satir_1Div.appendChild(satir_5Div);
satir_1Div.style.marginTop = '30px';
satir_3Div.style.marginTop = '10px';
satir_4Div.style.marginTop = '10px';
satir_5Div.style.marginTop = '10px';
satir_1Div.style.backgroundColor = "#18A2D9";
satir_1Div.style.padding = "10px";
satir_1Div.style.borderRadius = "2em";
var formId = document.getElementById("sayilarForm");
formId.appendChild(satir_1Div);
}
The code that add sequence number of created dynamically element to a hidden element and calling the Ajax code.
function ismiHiddenaEkle(name){
var hiddenEleman = document.getElementById("grupNoTutan");
hiddenEleman.value = name;
hesaplaServleteGonder();
}
The Javascript code that contain Ajax.
function hesaplaServleteGonder(){
var butonAdi= document.getElementById("grupNoTutan").value;
var grup_no = butonAdi.charAt(0);
var i = 1;
var birinciKokDerecesi;
var birinciKatsayi;
var birinciKokIciDeger;
var ikinciKokDerecesi;
var ikinciKatsayi;
var ikinciKokIciDeger;
var sonuc;
birinciKokDerecesi = document.getElementById(grup_no + "_kokDerecesi_" + i).value;
birinciKatsayi = document.getElementById(grup_no + "_kokKatsayi_" + i).value;
birinciKokIciDeger = document.getElementById(grup_no + "_kokIciDeger_" + i).value;
sonuc = document.getElementById(grup_no + "_sonuc");
i= i + 1;
ikinciKokDerecesi = document.getElementById(grup_no + "_kokDerecesi_" + i).value;
ikinciKatsayi = document.getElementById(grup_no + "_kokKatsayi_" + i).value;
ikinciKokIciDeger = document.getElementById(grup_no + "_kokIciDeger_" + i).value;
i = 1;
$.ajax({
type:'POST',
url:'/TYT_Mat_Soru_Cozumu_Java_war_exploded/Servlet/HesaplamaIslemleri',
dataType: 'json',
contentType:'application/json',
data: $('#sayilarForm').serialize() ,
cache:false,
success:function(data){
alert(data);
$('#sonuc').text(responseText);
},
error:function(){
alert('error');
}
});
}
The servlet is below.
#WebServlet("/Servlet/HesaplamaIslemleri")
public class HesaplamaIslemleri extends HttpServlet {
#Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter out = resp.getWriter();
StringBuilder sb = new StringBuilder();
BufferedReader br = req.getReader();
String str;
while( (str = br.readLine()) != null ){
sb.append(str);
}
System.out.println(sb.toString());
resp.getWriter().print(sb.toString());
}
#Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
doPost(req,resp);
}
}
When i click the button , a new page is loading and there are values with their names in the page.
Like this grupNoTutan=1_hesaplaButon&1_kokDerecesi_1=2&1_kokKatsayi_1=4&1_kokIciDeger_1=2&1_kokDerecesi_2=2&1_kokKatsayi_2=8&1_kokIciDeger_2=2&1_sonuc=&1_hesaplaButon=
Can anyone help?
Firstly, the POST request you are making to your HTTP Resource is not AJAX. If you want to asynchronously make an HTTP Request, get the response and write to DOM without full page refresh, please check out the classic XmlHttpRequest first and research about other methods. On a high level, your task will go something like this,
Construct the UI portion in JavaScript, if you want to do something dynamic.
For Static portions, use a separate CSS file and move your styling to it. Don't create all HTML elements and CSS Styling in JavaScript unless you need everything to be dynamic.
Understand what you want to return from your server side.
Do you want to return formatted HTML directly from server side? Or return data in formats like JSON or XML and get hold of returned AJAX response in client and manipulate the DOM (in your case the 'result' text box).
I solved the problem with that way. Servlet and javascript codes are below. Firstly, I breaked into pieces the json data to understand the structure. Then, I proccessed the data according to the which portion is array and which portion is object. (Created dynamically elements sequence number is storing in hidden element that named('grupNoTutan')
Javascript:
//Read the content of elements that created dynamically
var butonAdi= document.getElementById("grupNoTutan").value;
var grup_no = butonAdi.charAt(0);
var i = 1;
var birinciKokDerecesi;
var birinciKatsayi;
var birinciKokIciDeger;
var ikinciKokDerecesi;
var ikinciKatsayi;
var ikinciKokIciDeger;
var sonuc;
var operator = document.getElementById("operator").textContent;
//var url = "#" + grup_no + "_kokDerecesi_" + i
//var textboxvalue = $("'" + url + "'").val();
var birKokD = grup_no + "_kokDerecesi_" + i;
var birKokK = grup_no + "_kokKatsayi_" + i;
var birKokID = grup_no + "_kokIciDeger_" + i;
birinciKokDerecesi = document.getElementById(grup_no + "_kokDerecesi_" + i).value;
birinciKatsayi = document.getElementById(grup_no + "_kokKatsayi_" + i).value;
birinciKokIciDeger = document.getElementById(grup_no + "_kokIciDeger_" + i).value;
sonuc = document.getElementById(grup_no + "_sonuc");
i= i + 1;
var ikiKokD = grup_no + "_kokDerecesi_" + i;
var ikiKokK = grup_no + "_kokKatsayi_" + i;
var ikiKokID = grup_no + "_kokIciDeger_" + i;
ikinciKokDerecesi = document.getElementById(grup_no + "_kokDerecesi_" + i).value;
ikinciKatsayi = document.getElementById(grup_no + "_kokKatsayi_" + i).value;
ikinciKokIciDeger = document.getElementById(grup_no + "_kokIciDeger_" + i).value;
i = 1;
//send request to server
let url = '/TYT_Mat_Soru_Cozumu_Java_war_exploded/Servlet/HesaplamaIslemleri';
let xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencode");
var data;
data = JSON.stringify({
"birinci":[{
birKokD: birinciKokDerecesi,
birKokK: birinciKatsayi,
birKokID: birinciKokIciDeger}],
"ikinci":[{
ikiKokD: ikinciKokDerecesi,
ikiKokK: ikinciKatsayi,
ikiKokID: ikinciKokIciDeger
}],"operator": operator
});
xhr.send(data);
xhr.onload = function(){
sonuc.readOnly = true
sonuc.value = xhr.responseText;
}
Servlet Codes :
// Business Logic
KokluSayiIslemleriImpl business = new KokluSayiIslemleriImpl();
// Reading Request Header
StringWriter writer = new StringWriter();
StringBuilder buffer = new StringBuilder();
BufferedReader reader = req.getReader();
String line;
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
String data = buffer.toString();
JSONObject jsonObj = new JSONObject(new String(data));
// Creating the first object with data that getting from header
JSONArray birinci = new JSONArray();
birinci.put(jsonObj.get("birinci"));
JSONObject birinciSayi = birinci.getJSONArray(0).getJSONObject(0);
int kokDerecesi_1 = Integer.parseInt(birinciSayi.getString("birKokD"));
double kokIciDeger_1 = Double.parseDouble(birinciSayi.getString("birKokID"));
int kokKatsayi_1 = Integer.parseInt(birinciSayi.getString("birKokK"));
KokluSayi koklusayi_1 = new KokluSayi(kokDerecesi_1,kokIciDeger_1,kokKatsayi_1);
// Veri Sırası Test
System.out.println(koklusayi_1.getKokDerecesi() + " / " + koklusayi_1.getKatsayi() + " / " + koklusayi_1.getKokIciDeger());
// Creating the second object with data that getting from header
JSONArray ikinci = new JSONArray();
ikinci.put(jsonObj.get("ikinci"));
JSONObject ikinciSayi = ikinci.getJSONArray(0).getJSONObject(0);
int kokDerecesi_2 = Integer.parseInt(ikinciSayi.getString("ikiKokD"));
double kokIciDeger_2 = Double.parseDouble(ikinciSayi.getString("ikiKokID"));
int kokKatsayi_2 = Integer.parseInt(ikinciSayi.getString("ikiKokK"));
KokluSayi koklusayi_2 = new KokluSayi(kokDerecesi_2,kokIciDeger_2,kokKatsayi_2);
// Veri Sırası Test
System.out.println(koklusayi_2.getKokDerecesi() + " / " + koklusayi_2.getKatsayi() + " / " + koklusayi_2.getKokIciDeger());
// Getting the operator(which operation will processing)
char operator = jsonObj.getString("operator").charAt(0);
KokluSayi sonuc = business.dortIslem(koklusayi_1,koklusayi_2,operator);
//send result back to client
resp.getWriter().write("D :" + sonuc.getKokDerecesi() + " - " + "K :" + sonuc.getKatsayi() + " - " + "D :" + sonuc.getKokIciDeger());
Edit: Add reading content of elements that created dynamically code portion

Random Images without Links

Is there a way to make the below javascript just display the random images with out a link?
var imagenumber = 10 ;
var randomnumber = Math.random() ;
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
var URLs = new Array() ;
images = new Array
images[1] = "images/headerpics/fall/fall17.png"
images[2] = "images/headerpics/fall/fall1.png"
images[3] = "images/headerpics/fall/fall2.png"
images[4] = "images/headerpics/fall/fall3.png"
images[5] = "images/headerpics/fall/fall4.png"
images[6] = "images/headerpics/fall/fall5.png"
images[7] = "images/headerpics/fall/fall6.png"
images[8] = "images/headerpics/fall/fall7.png"
images[9] = "images/headerpics/fall/fall8.png"
images[10] = "images/headerpics/fall/fall9.png"
var image = images[rand1] ;
var linknumber = 1 ;
var img1 = Math.round( (linknumber-1) * randomnumber) + 1 ;
links = new Array
links[1] = "index.htm"
var link = links[img1];
document.write('<a href="' + link + '"><img src="' + image + '"
border="0"></a>') ;
Thanks for any help!
Just Remove the Anchor (<a>) tag from the document.write
document.write('<img src="' + image + '"border="0">');

File Manipulation in Javascript

I would like to take one large file in javascript and read through it byte by byte and separate every other byte into one file or another but i can't seem to even print out a single byte from a .txt file
var control = document.getElementById("your-files");
files = control.files;
len = files.length;
var test = document.getElementById("test");
test.value = "Filename: " + files[0].name;
test.value += "\n" + "Type: " + files[0].type;
test.value += "\n" + "Size: " + files[0].size + " bytes";
var blob = files[0].slice(0, 1000);
test.value += "\n" + blob;
var myReader = new FileReader();
test.value += "\n" + myReader.readAsText(blob);
test.value += "\n" + myReader.readAsBinaryString(blob);
I can print out the file size type and name but trying to print a blob i get it listed as just an object blob
example
Filename: test.txt
Type: text/plain
Size: 9604 bytes
[object Blob]
undefined
All I need to do is to add the file creation now that I can actually use the blobs.
function SplitFile(){
var control = document.getElementById("your-files");
files = control.files;
len = files.length;
var test = document.getElementById("test");
var i = 0;
while (i < len){
test.value += i + "\n";
test.value += "Filename: " + files[i].name;
test.value += "\n" + "Type: " + files[i].type;
test.value += "\n" + "Size: " + files[i].size + " bytes";
num_files = document.getElementById("piece-up").value;
test.value += "\n" + "Number of files: " + num_files;
var file_length = files[i].size;
var slice_size = 1000;
var remainder = file_length % slice_size;
var num_large = file_length - remainder;
var num_loops = num_large / slice_size;
var slice_0 = 0;
var slice_1 = slice_size;
var q = 0;
while(q< num_loops){
var myReader = new FileReader();
myReader.readAsText(files[i].slice(slice_0, slice_1));
myReader.onload = function(event) {
var contents = event.target.result;
test.value += "\n" + contents;
};
slice_0 = slice_0 + slice_size;
slice_1 = slice_1 + slice_size;
q++;
}
var myReader = new FileReader();
slice_0 = slice_1 - slice_size;
slice_1 = slice_1 + remainder - slice_size;
myReader.readAsText(files[i].slice(slice_0, slice_1));
myReader.onload = function(event) {
var contents = event.target.result;
test.value += "\n" + contents;
};
i++;
}
}

Categories

Resources