|
Finally could apply a solution:
Replace the way how it's show the result from the ajax live search to this:
<div>
<div>
<div>
<div class="child" data-id="' . $codice . '" data-id2="' . $articolo . '"><span>COD: ' . $codice . ' - DESC: ' . $articolo . '</span></div>
</div>
</div>
<div>
<div id="resultado"></div>
</div>
For the Javascript, replace it with JQuery:
<script type="text/javascript">
$(document).ready(function(){
$(".child span").click(function(){
code = $(this).parent().attr('data-id');
articolo = $(this).parent().attr('data-id2');
window.opener.$('#codice').val(code);
window.opener.$('#articolo').val(articolo);
window.close();
});
})
</script>
Thank you all.
Valter.
|
|
|
|
|
vlafratta wrote: $query = $sql = "SELECT * FROM spesa_articoli_disponibili WHERE Codice_Articolo_CAPP LIKE '%" . $search . "%' OR ARTICOLO_Descrizione LIKE '%" . $search . "%'";
Don't do it like that!
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
PHP: SQL Injection - Manual[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am just starting to learn JavaScript and am following an online course my company provides for IT Training. I have set up my environment as instructed, created my “Hello World!” and more.
We have not yet gotten to the Functions section, but the instructor created a utility.js file as follows:
Function showMessage(message) {
document.getElementById(‘message’).textContent = message;
}
However, as I begin entering in “showMessage” it is underlined in red squiggly line. So I slowly re-entered it to let pre-fill find the command “sho” it stops. ShowMessage is not available to use.
I am learning how to use both home.js and utility.js files to modify webpage, index.html, by placing an “id=“message” to change the index.html based on a home.js file that contains “showMessage(“Changes....”);
But the real issue is the Function missing from my “libraries or binary” files?
Thank you to anyone that may be able to answer why that Function may be missing or if it can be added. If left as is, the webpage when refreshed does not display Changes....
Sincerely, 60 year old learning JavaScript so I can quickly learn JSON to be able to make API calls via LAMBDA to leverage CloudFormation templates to build our stacks in AWS Cloud.
Thanks again, life-long learner,
VinManinho
|
|
|
|
|
|
Here is the code below I am hoping for help on. What I believe ought to happen is ten randomly colored/ shaped lines are successively drawn 1 every 500ms over 5 seconds in the <canvas> box. But all I am getting is a black canvas box.
All "//" and "NOTES" are IMPORTANT!
<html>
<head>
</head>
<body>
<canvas id="myCan" style="background: black;" width=720 height=420>
</canvas>
<script>
var canv = document.getElementById('myCan');
var ctx = canv.getContext('2d');
var t = 500; // time iteration
function draw() { // - - draw
ctx.beginPath();
c1x.canv.width*Math.random(); // bezier control 1 NOTES: original code has height ... so try please with your solutions
c1y.canv.height*Math.random(); // bezier control
c2x.canv.width*Math.random(); // bezier control 2 NOTES: original code has height ... so try please with your solutions
c2y.canv.height*Math.random(); // bezier control
x.canv.width*Math.random(); // random point
y.canv.height*Math.random();
x1.canv.width/2; // mid-point
y1.canv.height/2;
ctx.moveTo(x1, y1); // starting point
ctx.bezierCurveTo(c1x, c1y, c2x, c2y, x, y); // bezier curve
ctx.closePath();
ctx.lineWidth = Math.random()*20;
ctx.strokeStyle = hsl(' + Math.random()*360 + ', 50%, 50%); // color of bezier beam
ctx.shadowColor = 'white';
ctx.shadowBlur = Math.random()*50;
ctx.stroke();
ctx.strokeRect(c1x, c1y, 1, 1);
ctx.strokeRect(c2x, c2y, 2, 2);
}
draw();
setInterval(draw, t); // internal timer
setInterval(function() {ctx.clearRect(0, 0, canv.width, canv.height)}, 10*t);
// 10 shapes, '10*t
// 9 shapes, 9*t etc.
</script>
</body>
</html>
That is all.
Thank you.
|
|
|
|
|
There are a couple of problems with the code. The lines c1x.canv... down to y1.canv... should be assigning values to variables:
var c1x = canv.width*Math.random();
var c1y = canv.height*Math.random();
var c2x = canv.width*Math.random();
var c2y = canv.height*Math.random();
var x = canv.width*Math.random();
var y = canv.height*Math.random();
var x1 = canv.width/2;
var y1 = canv.height/2;
The other problem is the stroke style, where the hsl value must be quoted properly:
ctx.strokeStyle = 'hsl(' + Math.random()*360 + ', 50%, 50%)';
|
|
|
|
|
function generateLayout(seats, zIndex) {
var busLayoutHtmlTmpl = '';
var maxNoOfColumns = 0;
var missingPathWayRowNO = -1;
var missingPathWayRowNOTmp = 0;
var isfirtRow = 0;
var isDriverSeat = true;
var rowSeatValues = [];
var columnSeatValues = [];
_.each(seats, function (columnSeats, rowIndex) {
if (isfirtRow == 0) {
missingPathWayRowNOTmp = rowIndex;
isfirtRow = 1;
} else {
if (parseInt(missingPathWayRowNOTmp) + 1 != rowIndex) {
missingPathWayRowNO = parseInt(missingPathWayRowNOTmp) + 1;
} else {
missingPathWayRowNOTmp = parseInt(missingPathWayRowNOTmp) + 1;
maxNoOfColumns = columnSeats.length > maxNoOfColumns ? columnSeats.length : maxNoOfColumns;
}
}
});
var v = [];
_.each(zIndex, function (seats, t) {
$.inArray(seats, v) === -1 && v.push(seats)
}),
_.each(seats, function (columnSeats, rowIndex) {
_.each(columnSeats, function (seat, columnIndex) {
if ($.inArray(seat.x, rowSeatValues) === -1) {
rowSeatValues.push(seat.y);
}
if ($.inArray(seat.y, columnSeatValues) === -1) {
columnSeatValues.push(seat.y);
}
});
});
var seatLayOutMax= new Array();
var count = 0;
_.each(rowSeatValues, function (row, columnIndex) {
seatLayOutMax[row] = new Array();
_.each(columnSeatValues, function (seat, columnIndex) {
seatLayOutMax[row][seat] = "";
});
});
_.each(seats, function (columnSeats, rowIndex) {
_.each(columnSeats, function (seat, columnIndex) {
seatLayOutMax[seat.x][seat.y] = seat
});
});
var pathComparision = 0; var enterInRowsCount = 0;
_.each(seatLayOutMax, function (seats, index) {
busLayoutHtmlTmpl += '<tr>';
_.each(seats, function (col, ind) {
var seat = col;
if (seat == undefined) { return; }
pathComparision = seat.x;
if (seat != "") {
var l = seat.height;
var w = seat.width;
if (l == 1 && w == 1) {
busLayoutHtmlTmpl += '<td title="Seat : ' + seat.id + 'style="width:8%; padding:2px;"><div id="div' + seat.seat_no + "_" + '</div></td>';
} else if (l == 1 && w == 2) {
busLayoutHtmlTmpl += '<td title="Seat : ' + seat.id + 'style="width:8%; padding:2px;"><div id="div' + seat.seat_no + "_" + ' </div></td>';
} else if (l == 2 && w == 1) {
if (rowSeatValues.height == 1) {
busLayoutHtmlTmpl += '<td title="Seat : ' + seat.id + 'style="width:8%; padding:2px;" rowspan="2"><div id="div' + seat.seat_no + "_" + '</div></td>';
} else {
busLayoutHtmlTmpl += '<td title="Seat : ' + seat.id + 'style="width:8%; padding:2px;"><div id="div' + seat.seat_no + "_" + '</div></td>';
}
}
} else {
busLayoutHtmlTmpl += '<td></td>';
}
});
if (seats === undefined && busLayoutHtmlTmpl != "<tr>" && !busLayoutHtmlTmpl.includes('<tr><td><div style="width: 28px; height: 24px; margin-right: 5px;"></div></td><td></td></tr>')) {
busLayoutHtmlTmpl.replace('<tr></tr>', '');
busLayoutHtmlTmpl += '<tr><td><div style="width: 28px; height: 24px; margin-right: 5px;"></div></td><td></td></tr>';
} else {
busLayoutHtmlTmpl += '</tr>';
}
});
return busLayoutHtmlTmpl;
}
function SeatLayout() {
$.ajax({
url: "seats.json",
dataType: "text",
success: function(data) {
var json = $.parseJSON(data);
designCanvas(json);
}
});
}
function designCanvas(json) {
var seatSelected = [];
var divLower = document.getElementById('tblLowerSeat');
var divUpper = document.getElementById('tblUpperSeat');
var lowerSeats = [];
var upperSeats = [];
if(json.seats.z === 0){
lowerSeats.push(json.seats);
}
if(json.seats.z === 1){
upperSeats.push(json.seats);
}
lowerSeats = lowerSeats.sort(function (a, b) { return b.id - a.id; });
upperSeats = upperSeats.sort(function (a, b) { return b.id - a.id; });
var r = [];
lowerSeats.forEach(function (e) {
if (r.indexOf(e.x) == -1) { r.push(e.x); }
});
var g = new Array(r.length);
for (var i = 0; i < r.length; i++) {
g[i] = new Array();
for (var j = 0; j < lowerSeats.length; j++) {
if (lowerSeats[j].x == r[i]) {
g[i].push(lowerSeats[j]);
}
}
}
htmlLower = generateLayout(g, 0);
divLower.innerHTML = htmlLower;
}
<button class="btn btn-primary" id="btnViewSeat" onclick="SeatLayout();">
View Seats class="fa fa-arrow-circle-down">
</button>
<p id="demo"></p>
<link href="/TPT-2020/Assets/css/seatStyle.css" rel="stylesheet" />
<link href="https://www.jqueryscript.net/css/jquerysctipttop.css" rel="stylesheet" type="text/css">
<link href="/TPT-2020/Assets/css/bootstrap.min.css" rel="stylesheet" />
<div id="Viewseatcollapse" class="collapse busseatmng" style="display:inherit">
<div class="col-sm-12 card">
<div class="card-body">
<div class="row">
<div class="col-sm-8">
<div class="upperbusdivwrp" id="divSeatsUpper">
<div class="row busseatstructure">
<div class="col-sm-12 bg-dark pd-10 text-white text-center"><h5>Upper Deck</h5></div>
<div class="col-sm-12 busseatsinner">
<div class="row">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-1 col-1 driver"></div>
<div class="col-sm-11 col-11">
<table id="tblUpperSeat">
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="lowerbusdivwrp">
<div class="row busseatstructure">
<div class="col-sm-12 bg-dark pd-10 text-white text-center"><h5>Lower Deck</h5></div>
<div class="col-sm-12 busseatsinner">
<div class="row">
<div class="col-sm-12">
<div class="row">
<div class="col-sm-1 col-1 driver"><img src="/TPT-2020/images/stairing.png"></div>
<div class="col-sm-11 col-11">
<table id="tblLowerSeat">
<tbody>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="/TPT-2020/scripts/BindData1.js"></script>
<script type="text/javascript" src="/TPT-2020/scripts/GetDynamicSeats2.js"></script>
|
|
|
|
|
You seem to have forgotten to ask a question or describe a problem.
Just dumping all of your code and telling us "there is some problem", without providing any details of what that problem is, doesn't make a good question.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I have a global Array.
And there are multiple asynchronous events getting fired from different ends in the code.
In one of the events - Event1(), I'm iterating all the items in the global Array and using the values.
In another event Event2(), I'm removing a particular item from the global Array.
We have no guarantee about the timing or sequence of the event triggers.
Will this ever land in a crash? & How do we safeguard this.
modified 11-Feb-20 5:43am.
|
|
|
|
|
Unless you're using web workers[^], Javascript is single-threaded. Callbacks from async operations will be queued and executed on a single thread, so you don't need to worry about synchronizing access to your global state.
Even with web workers, it's hard to cause problems:
However, since web workers have carefully controlled communication points with other threads, it's actually very hard to cause concurrency problems. There's no access to non-threadsafe components or the DOM. And you have to pass specific data in and out of a thread through serialized objects. So you have to work really hard to cause problems in your code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Great answer. Happy to know about the Web Worker.
I was thinking if there happens a context-switch between the Async, altering the count of the Array by deleting an element, & thus making the iteration in another code block go out of scope with the index.
I see this is never possible. Thanks to the single-threaded design. :+1:
modified 11-Feb-20 7:32am.
|
|
|
|
|
ugent help please! here my criteria is to drag 3 images and drop them in 3 different locations. validate before dropping in the location if it already has an image, if yes them pop up a message.
Quick response will be highly appreciated. Thanks!
|
|
|
|
|
You need to provide much more detail of your problem.
|
|
|
|
|
here my criteria is to drag 3 images and drop them in 3 different locations. validate before dropping in the location if it already has an image, if yes them pop up an error message.
Basically how do I capture drop location ID where the image is dropped?
Can someone please help me out urgenlty on this?
|
|
|
|
|
There's a secret error somewhere in your secret code. You should fix that.
Seriously, how do you expect anyone here to help you fix your code, when you haven't shown us any of your code?
We can't see your screen. We can't access your computer. We can't read your mind. All we have to work with is what you type in the "message" box. If you can't explain the problem clearly, then we can't help you.
And adding "urgent" and "quick response" to your questions simply tells us that you can't manage your own time. It's not going to force us to answer your unanswerable question any quicker.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
A sign that I've appreciated in a couple of different supply rooms:
"A lack of planning on your part does not constitute an emergency on mine"
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
Member 14732785 wrote: validate before dropping in the location if it already has an image, Simple. Write code for the drop event and to check if the img tag already has a src attribute.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
You should probably work on one DND interface first, and then create 2 more of them and DND each image to a specific DND box. Get the hang of DND first and how it works. It's not as easy as it sounds and DND has some events you have to listen for.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
function isAvgWhole(arr) {
return Number.isInteger(arr.reduce((accum, val) => accum + val) / arr.length)
}
function isAvgBowl(arr)
{
return Number.isInteger(arr.reduce(function(accum,val)
{
return (accum+val)/arr.length
}))
}
console.log(isAvgWhole([1,1,1,1]))
console.log(isAvgBowl([1,1,1,1]))
|
|
|
|
|
Because you're using two completely different calculations:
Method 1:
Sum up all of the items in the array. Divide the sum by the length of the array.
arr.reduce((accum, val) => accum + val) / arr.length
var accum = arr[0];
for (var i = 1; i < arr.length; i++) {
accum = accum + arr[i];
}
var result = accum / arr.length;
Method 2:
For each value in the array, add that value to the accumulator, and divide the intermediate result by the length of the array.
arr.reduce((accum, val) => (accum + val) / arr.length)
var accum = arr[0];
for (var i = 1; i < arr.length; i++) {
accum = accum + arr[i];
accum = accum / arr.length;
}
var result = accum;
Step through both methods with a debugger, or write out the steps on a piece of paper, and it should be obvious why the second method is wrong.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hey,
I am solving a problem on hackerrank(https://www.hackerrank.com/challenges/compare-the-triplets/problem?h_r=next-challenge&h_v=zen). The problem states to complete the function
compareTriplets which must return an array of two integers, the first being ALice's score and the secoond being Bob's.
compareTriplets has the following parameter(s):
a: an array of integers representing Alice's challenge rating
b: an array of integers representing Bob's challenge rating
For more detail on the problem, refer to the following link:
https://www.hackerrank.com/challenges/compare-the-triplets/problem?h_r=next-challenge&h_v=zen
For the same challenge i wrote the following solution:
function compareTriplets(a, b) {
for (let i = 0; i < 4; i ++) {
points=[];
pointsArray=[];
if (a[i] > b[i]) {
points[i]=1;
pointsArray.push(points[i])
}
if (a[i] === b[i]) {
points[i]=0;
}
if (b[i] > a[i]) {
points[i]=1;
pointsArray.push(points[i])
}
return pointsArray;
}
}
The problem states that the output should be like [1,1] i.e. [points earned by alice, points earned by bob]
But somehow it displays a array with four elements with the values [1], [], [1], []
Refer to https://ibb.co/GCkwM9j for further details.
Can anybody suggest anything?
|
|
|
|
|
Manish169 wrote: Can anybody suggest anything? I would suggest to begin by solving it by hand with a pen and a piece of paper, so that you have a clear knowledge of input and output data as well as required steps. As of now the code you showed does not pass the simplest logic checks: you are provided with triplets (3 values) but operate on array of four values; you have an inconditional return statement inside a loop, rendering this loop kind of useless (it will return at the first iteration); you create two data structures where you only need one; you do not add points to existing values but rather overwrite them.
So, do it by hand first; there is no chance for you to come up with a proper algorithm if you cannot solve it yourself with a pen and paper.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
I am looking for a method to close the current tab of the browser window using JavaScript.
|
|
|
|
|
Unfortunately you can't for security purposes. You can only close windows that were opened by Javascript.
|
|
|
|
|
|