We help IT Professionals succeed at work.

JavaScript

123K

Solutions

42K

Contributors

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and  in almost every mainstream web browser.

Hi Experts

Could you point a eay to present a photo by giving its url location by using PHP/ Laravel?

Accordingly with

<div class="box-noticias">
	<a href="javascript:void(0);" onclick='....;' >
	{{$vitrine->url}}
	</a>                    
</div>

Open in new window


Actually the{{$vitrine->url}}  presents the url itself, something like:

https://xxxxx.blob.core.windows.net/xxx/vitrines/87w91898.BMP

So I need to render it to show as a image.

Thanks in advance.
0
Hi All

I want to be able to amend the link in this div but do not have access to the code, only the JS file, can someone advise the most basic JS code to amend this to simply "https://www.abc.co.uk/" please

 <div id="toplogo">
      <a title="Link to homepage" href="https://www.abc.co.uk/test/example">#</a>
</div>
0
I'm new to creating/using APIs and React, so can someone give me some pros and cons (or links to articles that detail the pros and cons) of making your api calls directly in your react app vs. creating a separate api application?
0
Hi Experts

Could you point why a Controller method code is subtly returning to a jquery ajax without running and returning OK to JS ?

Accordingly to:

Vitrine.prototype.salvar = function(){
    
  console.log ('JS salvar');
  
  $.ajax({
    url: '/vitrine/salvar',
    
    method: "POST",
    data: {
      _token: $('input[name="_token"]').val(),
      id: $('#id').val(),
      url: $('#url').val(),
      inicio: $('#inicio').val(),
      termino: $('#termino').val(),
      title: $('#title').val(),
      description: $('#description').val(),
      points: $('#points').val()
    },
    error:function(data){
      hotsite.openModalCustom("Erro", data.responseText, "Entendi", "error");
    },
    success: function(data){
      hotsite.openModalCustom("Sucesso ao salvar", data.retorno, "Entendi", "success");
      hotsite.closeModal('mEditor');
      //hotsite.vitrine.filtrar();
    }
  });
};

Open in new window


and Controller method:


 public function salvar(Request $request){
   
	 //Forcing an error
	 //aaa;
	
	
	// Otherwise subtly exit with no traces.
	info('xxx');
   
	dd('aaa');

	$id=$request->input('id');
	$url=$request->input('url');
	$inicio=$request->input('inicio');
	$termino=$request->input('termino');

	$titulo = $request->input('title');
	$descricao = $request->input('description');
	$pontuacao = $request->input('points');

	try{
		if($id != '' &&  $id > 0){
		  $vitrine = Vitrine::find($id);
		}

		if(empty($vitrine)){
		  $vitrine = new Vitrine();
		  $vitrine->created_at=new \DateTime();
		}
			
		$vitrine->title = $titulo;
		$vitrine->description = $descricao;
		$vitrine->points = CustomFuncs::brancoParaNulo($pontuacao);
		$vitrine->url = $url;
		$vitrine->validity_start = empty($inicio) ? null : CustomFuncs::formatarDataUS($inicio);
		$vitrine->validity_end = empty($inicio) ? null : CustomFuncs::formatarDataUS($termino);
		$vitrine->updated_at=new \DateTime();
		
		info($vitrine);
		
		
		$vitrine->save();

	} catch (\Exception $e) {
		return response()->json(new Resultado(true,'','Erro ao salvar o vídeo'), 400);
	}

	return response()->json(new Resultado(false,'','Vídeo cadastrado com sucesso'));

}

Open in new window



The forced error:

img015
Thanks in advance!
0
Below js code, everything is working except

document.getElementById("row_" + eventid).style.display = 'none';

When it <a></a> is clicked, I hope to delete or invisible on the selected <div></div>
Do you know what goes wrong?


 function AddQty(eventid,qty,price) {
        var qty_value = document.getElementById(qty).value;
        var price_value = document.getElementById(price).value;
        var eventid_value = document.getElementById(eventid).value;
        
        document.getElementById("qty").value = parseInt(document.getElementById("qty").value) + parseInt(qty_value);
        document.getElementById("totalamount").value = parseFloat(document.getElementById("totalamount").value) + parseFloat(price_value);

        document.getElementById("shoppingcart").innerHTML = document.getElementById("shoppingcart").innerHTML +
       "<div id='row_' " + eventid_value  + " class='col-fs-12'>" +
            eventid_value + " " + qty_value + " " + price_value + " " + "<a style='cursor: pointer;' onclick='Remove(" + eventid_value + ")'>x</a>";
        "</div>";
    }
    function Remove(eventid) {        
        alert('Hi ' + eventid);
        document.getElementById("row_" + eventid).style.display = 'none';
    }

Open in new window

0
Hi,

I have one file which is written in traditional javascript. Trying to convert the file to ES6 class. Sending both the files. I am getting error on calling the function in the constructor.

Please check.

Error:
 Error: TypeError: mechanics.Debug.apply is not a function
baseClass.txt
TraditionalJS.txt
ES6Format.txt
0
Here's the code that I'm working on:

async auth(email, password) {
   1) const isDev = (process.env.ENV == 'local' || process.env.ENV == 'dev');
	//console.log(email);
    2) let match = {
      email: email,
      active: true
    };

    try {
        3) let user = await this.loadUser(match);        
      // validate the password hash
      if (!isDev) {
        await this.checkPasswordHash(password, user.password);
      }

      return this.success(user);
    } catch (err) {
      console.log('Error: ', err);
      return this.error(err);
    }
  }

Open in new window


Here are my questions / explanations. Could you please either "proof" or answer my quandaries?

1 I've not seen this before: const isDev = (process.env.ENV == 'local' || process.env.ENV == 'dev');

I'm assuming it's something similar to a ternary IF statement, but what does it mean? And I'm just shooting from my hip as far as it being a ternary IF statement. Generally, when faced with this kind of thing, I'll refer to https://davidwalsh.name/php-ternary-examples, but this genuinely baffles me.

2 "match" is a variable that houses an array consisting of two key / value pairs: "email" and "active." "email" is one of the arguments being passed into the method, so that's going to be coming from the login page.

3 loadUser looks like this:

  loadUser(match={}) {
    return new Promise( async (resolve, reject) => {
      this.model.aggregate([
        {$match: match},
       

Open in new window

0
Hi Experts


Could you clear why this Controller method isn't called as expected?

Accordingly with a previous question this form have 02 phases

1st: Upload a picture to a defined path - In my tests by using  
use Illuminate\Support\Facades\Storage;

Open in new window

It's perfectly locally uploaded.


2nd  The image url and details must to be saved at the table Vitrines

So, this method is called

Vitrine.prototype.salvar = function(){
    
  console.log ('JS salvar');  // Pass here
  
  $.ajax({
    url: '/admin/vitrine/salvar',
    method: "POST",
    data: {
      _token: $('input[name="_token"]').val(),
      id: $('#id').val(),
      url: $('#url').val(),
      inicio: $('#inicio').val(),
      termino: $('#termino').val(),
      title: $('#title').val(),
      description: $('#description').val(),
      points: $('#points').val()
    },
    error:function(data){
      hotsite.openModalCustom("Erro", data.responseText, "Entendi", "error");
    },
    success: function(data){
      hotsite.openModalCustom("Sucesso ao salvar", data.retorno, "Entendi", "success");
      hotsite.closeModal('mEditor');
      //hotsite.vitrine.filtrar();
    }
  });
};

Open in new window


img008
This method is configured at routes

Route::post('/admin/vitrine/salvar',['uses'=>'admin\VitrineController@salvar'])->middleware('cadastro');

Open in new window


But it doesn't seen it's called at VitrineController

 public function salvar(Request $request){
 
       

Open in new window

0
This works:

<script>

$(document).ready(function() {
	
	const fetchData = () => {
	  const promise = new Promise((resolve, reject) => {
		setTimeout(() => {
		  resolve("Loose Cannon Fitness");
		}, 100);
	  });
	  return promise;
	};
	
	
	setTimeout( async () => {
	  console.log("Smith and Gone");
	  var text = await fetchData();
	  console.log(text);
	}, 200);


});

</script>

Open in new window


What I'm attempting to do is get a better understanding of Callbacks, Promises and Async / Await(s).

To do that, I started with a very basic example and just built on that - adding / editing things in order to match what represented the new paradigm.

Here's the basic Callback:

$(document).ready(function() {
	
	x = function(cb) {
		setTimeout(function() {
			console.log("Smith and Gone");
			cb();
		}, 200);
	}

	y = function() {
		console.log("Loose Cannon Fitness");
	}
	
	x(y);
	
});

Open in new window


Here's the same result structured using ES6:

$(document).ready(function() {
	
	x = (cb) => {
		setTimeout(function() {
			console.log("Smith and Gone");
			cb();
		}, 200);
	}

	let y = () => {
		console.log("Loose Cannon Fitness");
	}
	
	x(y);
	
});

Open in new window


Here it is written using Promises:

const fetchData = () => {
  const promise = new Promise((resolve, reject) => {
	setTimeout(() => {
	  resolve("Loose Cannon Fitness");
	}, 100);
  });
  return promise;
};

setTimeout(() => {
  console.log("Smith and Gone");
  fetchData()
  .then(text => {
	console.log(text);
  });
}, 200);

Open in new window


And here it is written using an Async / Await dynamic:

$(document).ready(function() {
	
	const fetchData = () => {
	  const promise = new Promise((resolve, reject) => {
		setTimeout(() => {
		  resolve("Loose Cannon Fitness");
		}, 100);
	  });
	  return promise;
	};
	
	setTimeout( async () => {
	  console.log("Smith and Gone");
	  var text = await fetchData();
	  console.log(text);
	}, 200);

});

Open in new window


Just for the sake of drill, I did this:

$(document).ready(function() {
		
	const fetchData = () => {
		setTimeout(function() {
			console.log("Loose Cannon Fitness");
		}, 200);
	}

       setTimeout( async () => {
       console.log("Smith and Gone");
       var text = await fetchData();
       console.log(text);
      }, 200);
 
});

Open in new window


What I wanted to do was make "fetchData" a regular ES6 function as opposed to something that was incorporating a Promise.

The result was an error that looked like this:

Smith and Gone
stunt.php:54 undefined
stunt.php:25 Loose Cannon Fitness


Line #54 was "console.log(text)."

I'm assuming that "undefined" is a result of the fact that "await" is expecting a Promise.

Is that correct?

That said, is there a way to do what I've got written above where my "setTimeout" function works as it "awaits" fetchData written as an anonymous funtion?

This isn't something I would use in a practical setting. Rather, it's something I'm putting together for my own edification

What do you think?

In an effort to figure it out for myself, I tried this:

	const fetchData = () => {
		setTimeout(function() {
			//console.log("Loose Cannon Fitness");
			//var text = "Loose Cannon Fitness";
			//return text;
			return "Loose Cannon Fitness";
		}, 200);
	}

Open in new window


That didn't work.

I tried this:


Open in new window

0
Hi all,

I have a vulnerability that is preventing my frontend's automated build.

I did a npm update and bower update, this caused new versions of dependencies to be included in my package.json and bower.json, all fine.

If I try the build the dependency error is still showing in two different locations:
node_modules/polymer-cli/node_modules/handlebars/dist/handlebars.js - v4.1.2

and

node_modules/bower/lib/node_modules/handlebars/dist/handlebars.js - v4.0.10

I don't understand why those versions were not updated even if I specifically requested the latest version for polymer-cli and bower.
I've searched everywhere in the codebase but I couldn't find any reference to those versions to update them.

Can you please help?
0
I'm [new to / learning] react and so I'm experimenting with code samples that I find and trying to understand concepts within the language. Why does this work when the button is clicked:

import React, { useState } from 'react';


const Home = props => {
  // Declare a new state variable, which we'll call "count"
  const [count, setCount] = useState(0);

  const manipulateSomeState = () => {
        setCount(() => (count + 1));
  };

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={manipulateSomeState}>
        Click me
      </button>
    </div>
    );
}

export default Home;

Open in new window


But this does not work when the button is clicked:
import React, { useState } from 'react';


const Home = props => {
  // Declare a new state variable, which we'll call "count"
  const [count, setCount] = useState(0);

  const manipulateSomeState = () => {
        setCount({count: count + 1});
  };

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={manipulateSomeState}>
        Click me
      </button>
    </div>
    );
}

export default Home;

Open in new window


If I can get an explanation in "laymen" (non technical) terms that would be great.  Everything is the same except the "manipulateSomeState" function within the functional component. For what its worth, when I look at the first version of the manipulateSomeState function (the one that breaks/doesn't work) it seems straight forward. In my mind I'm adding 1 to the count state variable. In the second version of manipulateSomeState (the version that works), it seems like I'm having to use an anonymous function to accomplish the same thing and it appears to me that this is more/overly complicated. What am I not understanding.



Thanks in advance.
0
Hey There,

I need a little help tweaking my script for determining a State based on a Phone Number areacode.

I have a form, which when you enter the phone number, a hidden field will be populated with the state.   The script is working if you enter the number in 111-111-1111 or 111111111 format, but if you do (111)-111-1111 or (111)111-1111 format, it displays none.  So How do i tweak this, so it will pull the state regardless of the format.  Website here - Website

form html
<div class="rounded-lp-form">
<div class="lp-form-header">
		<h1 style="text-align: center;">Schedule a demo</h1>
		<p style="text-align: center;"><span class="text-black">Already an existing customer?</span><br />
			<a href="https://buildertrend.com/company/contact-us/">Contact us here.</a>
		</p>
  </div>
  <form id="scedule-demo-lp-form" class="" action="https://go.buildertrend.com/l/464372/2020-02-04/7lw3vg" method="get">

<div>
    <input type="text" id="full_name" name="full_name" required placeholder="Full name" required/>
    <label for="full_name" class="hide-label">Full Name</label>
 </div>  
  <div>
    <input type="email" id="email" name="email" required placeholder="Email address" />
    <label for="email" class="hide-label">Email Address</label>
  </div>
  
<div>
	<input name="phone" id="phone" type="tel" placeholder="Phone number" required>
	<label for="phone" 

Open in new window

0
Hi Experts

Could you give me directions on how this JS uploading photo method is running?

-- web page script

<script>
  var jqXHRData;
  $(document).ready(function() {
    ZZZsite.video.filtrar();
    var pars = {
        _token:$('input[name="_token"]').val()
    };

    var resultImageUpload = function (data) {
        if (!data.result.erro) {
            localizacao = data.result.retorno.localizacao;
            $('#url').val(localizacao);
            $('#srcVideo').attr('src', localizacao);
            $("#box-video video")[0].load();
            return false;
        } else {
          ZZZsite.openModalCustom("Erro",'Erro ao subir vídeo.', "Entendi", "error");
          return false;
        }
    };

    var failImageUpload = function (data) {
          if (data.files[0].error) {
              ZZZsite.openModalCustom("Erro",'Erro ao subir vídeo.', "Entendi", "error");
              return false;
          }
    };

// --- DOES THIS PART ASKS TO SAVE ON A PATH (???)
    ZZZsite.InitFileUpload("file", "/admin/videos/salvarVideo", pars, resultImageUpload, failImageUpload);
//----------------------------------------


    $("#file").change(function () {
        if (jqXHRData) {
            jqXHRData.submit();
        }
        return false;
    });
  })
</script>

Open in new window



-- JS script
ZZZsite.prototype.InitFileUpload = function(
  input,
  url,
  pars,
  doneCallbackFunction,
  failCallbackFunction
) {
  "use strict";

  $("#" + input).fileupload({
    url: url,
    formData: pars,
    dataType: "json",
    type: "POST",
    add: function(e, data) {
      jqXHRData = data;
    },
    done: function(event, data) {
      if (
        doneCallbackFunction != undefined &&
        typeof doneCallbackFunction == "function"
      ) {
        doneCallbackFunction(data);
      } else {
        ZZZsite.openModalCustom("Erro", data, "Entendi", "error");
      }
    },
    fail: function(event, data) {
      if (
        failCallbackFunction != undefined &&
        typeof failCallbackFunction == "function"
      ) {
        failCallbackFunction(data);
      } else {
        ZZZsite.openModalCustom("Erro", data, "Entendi", "error");
      }
    }
  });
};

Open in new window



img001



At VideoController I found the method SalvarVideo ... (called at the page)

   public function salvarVideo(Request $request){
        $video=$request->file('file');

        if (!$request->hasFile('file')){
            $resultado=new Resultado(true,"","Nenhum arquivo foi selecionado.");
            return response()->json($resultado);
        } else {			
            $videoUrl = AzureStorage::saveFile($video,'videos');
        }

        $output = array(
            "localizacao" => $videoUrl,
        );

        $resultado=new Resultado(false,"",$output);

        return response()->json($resultado);
    }

Open in new window


After choosing a photo the textbox is filled with a location very unclear.

Since I'm still developing and need to test it, the correct here is to create a defined path to save the photo image file?

Thanks in advance!
0
Here's my Promise:

$(document).ready(function() {
	
	const fetchData = () => {
	  const promise = new Promise((resolve, reject) => {
		setTimeout(() => {
		  resolve("Loose Cannon Fitness");
		}, 100);
	  });
	  return promise;
	};

	setTimeout(() => {
	  console.log("Smith and Gone");
	  fetchData()
	  .then(text => {
		console.log(text);
	  });
	}, 200);

});

Open in new window


How would I convert that to an "async / await" dynamic?
0
The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.


<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <title>reCaptcha-test2.php</title>

    
  </head>
  <body>
    <?php
      echo "reCaptcha-test.php says hello"; 
      $url = 'https://www.themagnolia.com/reCaptcha-test-2.htm';
      $inputName;$inputEmail;$inputPhone;$inputMessage;$inputAddress;$inputCity;$inputState;$inputZipcode;$captcha;
      $captcha = filter_input(INPUT_POST, 'token', FILTER_SANITIZE_STRING);
        if (!$captcha) {
          <script>consol.log ("Quit No Captcha");</script>
          header ('location: https://www.themagnolia.com/reCaptcha-test-2.htm');
          exit ('Quit... token not found');
        }

        $secretKey = 'SECRET-KEY-GOES HERE';
        //$ip = $_SERVER['REMOTE_ADDR'];

        // post request to server
        $url = 'https://www.google.com/recaptcha/api/siteverify';
        $data = array('secret' => $secretKey, 'response' => $captcha);
        
        $options = array (
          'http' => array (
            'method'  => 'POST',
            'header'  => "Content-type: 

Open in new window

0
jQuery Radio Button on Change Function not working.

<script>
    (function ($) {
   $("input[name=shipping_method[0]]:radio").change(function () {
        alert('HOLA');
 });
}) (jQuery);
    </script>


	<ul id="shipping_method" class="woocommerce-shipping-methods">
									<li>
						<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate1" value="flat_rate:1" class="shipping_method"  /><label for="shipping_method_0_flat_rate1">Flat rate: <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#36;</span>102.00</span></label>					</li>
									<li>
						<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate3" value="flat_rate:3" class="shipping_method"  /><label for="shipping_method_0_flat_rate3">Fed Ex: <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#36;</span>39.00</span></label>					</li>
									<li>
						<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate4" value="flat_rate:4" class="shipping_method"  checked='checked' /><label for="shipping_method_0_flat_rate4">UPS: <span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#36;</span>39.00</span></label>					</li>
									<li>
						<input type="radio" name="shipping_method[0]" data-index="0" id="shipping_method_0_flat_rate5" value="flat_rate:5" class="shipping_method"  

Open in new window

0
Hi Experts


Could you point a way to avoid an user to vote more than one time at each picture on this Laravel view?

    <input type="hidden" id="hdnCurtiu" value="{{$curtiu}}">

        <div class="col-md-12 col-sm-12">

                <section class="row">
               
                        @foreach($vitrinesX->chunk(3) as $row)
                        
                            @foreach($row as $vitrine)
          
                          
                               <div class="col-sm-12 col-md-4">
                               
                                    @php 
                                        $currentUserId = auth()->user()->id;
                                        $hasUserVoted = $vitrine->liked_by->contains($currentUserId); 
                                    @endphp
                               
                                    <div class="box-noticias">
                                       	<a href="javascript:void(0);" onclick='hotsite.vitrine.abrirVitrine({{$vitrine->id}});' >
                	    				{{$vitrine->titulo}}
                	    			    </a>                    
                                    </div> 
                                    
                                    <p id="like" class="likes" @if (!$hasUserVoted ) onclick="hotsite.vitrine.salvarEscolha({{ $vitrine->id }}, 1)" @endif>
                                        <i class="fa fa-thumbs-up"></i> <span id="qtdeCurtiu_{{ $vitrine->id

Open in new window

0
I have 4 videos and 4 buttons on screen. I want to be able to efficiently loop over each on to add various javascript functions.
My code currently looks like this:

html
        <div class="video-item">
          <video controls>
            <source src="videos/testvt.mp4" type="video/mp4">
          </video>
          <button>play</button>
          <div class="video-title">Title</div>
        </div>

Open in new window


javascript
  var videoitem = document.querySelectorAll('.video-item'), i;
  for (i = 0, length = videoitem.length; i < length; i++) {
    elem = videoitem[i];

    $(elem).click(function(){
      var elemButton = elem+" button";
      openFullscreen(elemButton)
    });


    $(elem + " video").on('ended', function(){
      this.webkitExitFullscreen();
    });

  }

Open in new window

0
Hi Experts

Could you point a way to enable/ disable an "Like"  icon depending on the user had clicked on it before or not - considering on an available collection of data?


img014


Giving this actual Laravel running  view code:

	<div class='row'>


	{{ csrf_field() }}
    <input type="hidden" id="hdnCurtiu" value="{{$curtiu}}">

        <div class="col-md-12 col-sm-12">

                <section class="row">
               
                        @foreach($vitrinesX->chunk(3) as $row)
                        
                            @foreach($row as $vitrine)
                            
                            
                              @php $hasUserVoted = $vitrine->liked_by->contains($vitrine->id);
                              
                                    info($vitrine->linked_by);
                               @endphp
                          
                               <div class="col-sm-12 col-md-4">
                               
                               
                                    <div class="box-noticias">
                                       	<a href="javascript:void(0);" onclick='hotsite.vitrine.abrirVitrine({{$vitrine->id}});' >
                	    				{{$vitrine->titulo}}
                	    			    </a>                    
                                    </div> 
                                    
                                   	<p id="like" class="likes" 

Open in new window

0
search.png
The above image is a potential flow for a user doing a search of multiple, independent databases in a microservices architecture. We are considering using Kafka.

The basic flow is:
1. The UI initiates a search (keyword).
2. a Microservice receives the request on the backend.
3. Publishes the request, which is subscribed to by the myriad of databases (wrapped in microservices.)
4. The microservice (same or different) receives the responses and "collates" them.
5. The UI receives the collated data and displayed it.

The questions are:

1. How much of the UI should be run on the client-side, and how much on the server-side.

2. What is the best Javascript to use (to interface with Kafka, specifically. Angular, Node, React, ...?)

3. What is the best interface method for the UI to talk with Kafka (REST & web gateway, something else?)
0
Hi
I'm making my Javascript phone game,
but doing home-made sprite sheets isn't fitting right!

There must be a flawless way to put them together. - - Consider my current game needing an array of dozens of cards, (game related pics)
I have all my cards ready to pack together, example like this image:
truck icon
If I standardize their dimensions, is software like this, below, most appropriate for my needs?  i.e. Does it work? Is it a trojan horse? Is freeware like this ever hostile, btw? Is there a well-used, reliable alternative? It seems ideal.

sprite sheet maker

Thanks
0
Hi, following are 2 patterns of javascript code that I frequently use.
I suppose that there is a more "advanced" way to do it.

var found = false;
for (var i = 0; i < some_array.length; i++) {
    if (some_array[i].val == some_val) {
        found = true;
        break;
    }
}
if (found)
{
    // do something with some_array[i].
}

Open in new window


var found = false;
var key;
for (key in some_hashtable) {
    if (some_hashtable[key].val == some_val) {
        found = true;
        break;
    }
}
if (found)
{
    // do something with some_hashtable[key].
}

Open in new window

0
I have a HTML5/js web page that was working fine and stopped working a short time ago.  I have placed this web page temporally at: https://www.barnwellmd.com/temp/test.html so I can delete it after I close this question (it saves files on my server and sends me an email).  

The problem is when a user clicks on "Send to Dr. Office" a popup shows "<head><title>Not Acceptable!</title></head><body><h1>Not Acceptable!</h1><p>An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.</p></body></html>" and nothing is sent.

That button calls the sendCanvas() function:
function sendCanvas()
{
      if (checkFields()) return;
      clearGray();
      createPrint();
      var testCanvas = document.getElementById("imageView");  
      var canvasData = testCanvas.toDataURL("image/png");
      //alert(canvasData);
      var ajax = new XMLHttpRequest();
      //alert ('https://www.barnwellmd.com/Uploadroutines/uploadbase64.php?name=' + document.form.ptname.value.replace(/ /g,"_"));
      ajax.open("POST",'https://www.barnwellmd.com/Uploadroutines/uploadbase64.php?name=' + document.form.ptname.value.replace(/ /g,"_"),false);
      //ajax.open("POST",'https://www.barnwellmd.com/Uploadroutines/uploadbase64.php',true);    
      ajax.setRequestHeader('Content-Type', 'canvas/upload');
      //ajax.setRequestHeader('Content-Type', 'application/upload');
      ajax.onreadystatechange=function()
      {
            if (ajax.readyState == 4)
            {
                  alert(ajax.responseText);
                  …
0
Hi Experts


Could you point a way to enable/ disable an like icon depending on the user had clicked the icon before or not?

Accordingly with:

img004
The user has the right of click the "Like" of  a photo once and after that he coudn't do nothing else, the like icon must to be disabled.
If the user reenter the page the like icon for the photo that had received a "like" must to stay disabled, also, by using the user's id.

The actual view:

@extends('layouts.appinterno')

@section('content')

	<div class='row'>

	{{ csrf_field() }}
    <input type="hidden" id="hdnCurtiu" value="{{ $curtiu }}">

        <div class="col-md-12 col-sm-12">
               
                <section class="row">
               
                        @foreach($vitrinesX->chunk(3) as $row)
                        
                            @foreach($row as $vitrine)
                          
                               <div class="col-sm-12 col-md-4">
                               
                                    <div class="box-noticias">
                                       	<a href="javascript:void(0);" onclick='xxx.vitrine.abrirVitrine({{$vitrine->id}});' >
                	    				{{$vitrine->titulo}}
                	    			    </a>                    
                                    </div> 
                                    
                                   	<p id="like" class="likes" onclick="xxx.vitrine.salvarEscolha({{ $vitrine->id 

Open in new window

0
Need to install Node.js on my Windows 10 .NET Development machine

I need to install Node so I can install jsinspect so I can find code duplication that got there through heavy us of copy-paste.

I have worked with Node in the past. But, I want to be 100% sure I am not going to in any way harm my Windows PC, since that is my bread-and-butter machine.

Can you provide me the safest set of steps to do this?

Thanks
0

JavaScript

123K

Solutions

42K

Contributors

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and  in almost every mainstream web browser.