modifying env.const.js from index.html in reactjs

We are trying to modify env.const.js file from index.html

index.html

<body>
<script> 
window['localConfig'] = {    // <---------------localConfig can be changed from index.html
   id: 'local123',
   appServer: 'https://local-qa.com/'
}
</script> 
</body>

env.const.js

let URLS = {
  development: {
    id: '456',
    appServer: 'https://abc-qa.com/'
  }
}



// getting `localConfig` from index.html

let API_URL = window['localConfig'] ?  { ...URLS['development'], ...window['localConfig']} : URLS['development'];
module.exports = API_URL;

Getting error as :-

window[‘localConfig’] is not defined

I want to call two IDs with one anchor tag, one in the right sidebar and one in iframe (both IDs are same)

I want to call two IDs with one anchor tag, one in the right sidebar and one in iframe (both IDs are same). onclick functions can also try. I have tried with same ids but its not working.

My requirement.

  1. when I click link from left sidebar, ID should be called in right sidebar and iframe.

please note: ids are same with iframe.

$(document).ready(function () {
    $('.nav ul li:first').addClass('active');
    $('.tab-content:not(:first)').hide();
    $('.nav ul li a').click(function (event) {
        event.preventDefault();
        var content = $(this).attr('href');
        $(this).parent().addClass('active');
        $(this).parent().siblings().removeClass('active');
        $(content).show();
        $(content).siblings('.tab-content').hide();
    });
});
*,
.row {
  margin: 0;
  padding: 0;
}
body {
  font-family: "Author", sans-serif !important;
  font-size: 16px;
  font-weight: normal;
  letter-spacing: 0.5px;
  color: white;
  background: black;
}
.bg-dark,
.btn-dark {
  background: #0d1117 !important;
}
.nav .btn {
  border: none;
  letter-spacing: 0.5px;
}
.border-bottom {
  border-bottom: 1px solid #20252c !important;
}
.border-end {
  border-right: 1px solid #20252c !important;
}
.border-start {
  border-left: 1px solid #20252c !important;
}
.publish-btn {
  letter-spacing: 0.5px;
  font-size: 95%;
}
.icon-sm {
  width: 1.4em;
}
.icon-xs {
  width: 1em;
}
.nav .btn-link {
  color: white;
  text-decoration: none;
}
.nav .bg-success {
  background-color: #1987545e !important;
  font-weight: normal;
  letter-spacing: 1px;
}
.nav a {
  color: white !important;
  text-decoration: none;
}
.nav ul li {
  margin-bottom: 0.5rem !important;
}
#iframe {
  transition: 0.8s;
}
.iframe {
  border: 2px solid rgb(120, 120, 120);
  border-radius: 0.5em;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}
.vh-100 {
  height: 93.5vh !important;
}
.center {
  position: relative;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  height: 100%;
  width: 100%;
}
.form-control {
  background: #12171f !important;
  border: 1px solid #20252c !important;
  border-radius: 0.15rem;
  color: white !important;
}
dl,
ol,
ul {
  list-style: none;
  padding-left: 0rem;
}
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<link
  href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
  rel="stylesheet"
  integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
  crossorigin="anonymous"
/>
<link href="https://udee.space/db2/db/assets/css/style.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div class="row vh-100 bg-dark">
  <div class="col-2 border-end px-4 p-2 pt-5 text-white">
<div class="nav">
  <ul>
    <li>
      <a href="#section-site-identity"
        ><i data-feather="command" class="icon-xs"></i> &nbsp; Logo</a
      >
    </li>
    <li>
      <a href="#usefulLinks" target="myIframe"
        ><i data-feather="heart" class="icon-xs"></i> &nbsp; Useful link</a
      >
    </li>
  </ul>
</div>
  </div>

  <div class="col-8">
<div class="center p-5" id="iframe">
  <div
    class="row text-white"
    style="
      background: rgb(120, 120, 120);
      border-top-left-radius: 0.5em;
      border-top-right-radius: 0.5em;
    "
  >
    <center>
      <i data-feather="globe" class="icon-xs"></i> domainname.com
    </center>
  </div>
  <iframe
    class="center shadow-lg iframe"
    src="https://udee.space"
    title=""
    name="myIframe"
  ></iframe>
</div>
  </div>

  <div class="col-2 border-start px-4 p-2 pt-5 text-white">
<div id="section-active" class="tab-content"><h6>Active div</h6></div>
<div id="section-site-identity" class="tab-content"><h6>logo div</h6></div>
<div id="usefulLinks" class="tab-content"><h6>Useful link</h6></div>
  </div>
</div>

Hide dynamic created div created using ngIf

I’m trying to create this div dynamically using jquery in angular

  let Word='<div style="position: relative;display: inline-block" *ngIf='+this.show+'">'+ word.trim() + '</div>'

Element is being created but i want to hide it on some condition like i was trying to use *ngIf='+this.show by default it should be hidden and when this.show is true then only this div should be visible.

Any solution Thanks.

Aide jeux du pendu en javascript , afficher lettre quand lettre trouvée [closed]

je suis en train d essayer de faire le jeux du pendu qui se joue à 2, je joueur 1 marque un mot et le joueur 2 doit essayer de trouver le mot. J’ai réussit à faire en sorte d’afficher autant de “” qu’il y a de caractères dans le mot mais je n’arrive pas à faire de sorte d’afficher la lettre dans le bon “” lorsque la lettre est bonne.

Voici mon code,merci d’avance

let motRentre = document.getElementById("motChercher");

const boutoncherchermot = document.getElementById("boutoncherchermot");
const trouvermotboutton = document.getElementById("trouvermotboutton");
const form1 = document.getElementById("chercherMot");
const form2 = document.getElementById("trouverleMot");
trouverMot = document.getElementById("trouverMot").value;
image = document.createElement('img');
let reponsetableau = [];
let motsecret = "";
const barre = document.getElementById("champs")
let lettre = "";


  function afficherbarre(event) {
      motsecret = motRentre.value;

      lettre = motsecret.split("");
      for (let i=0; i< lettre.length; i++)
      {
        reponsetableau[i] = " _ ";

         
        reponsetableau = document.createTextNode(reponsetableau[i])

         barre.appendChild(reponsetableau);
       
      }
  }


  /*
let lettrerentre = trouverMot.value;
lettre = lettrerentre.split("");
for (let i=0; i< lettre.length; i++)
{
  if(texte[i] == lettre){
   reponsetableau=lettre;

}
}*/



          

boutoncherchermot.addEventListener("click", ajouterlemot);
form1.addEventListener("click", boutoncherchermot);
function ajouterlemot(event) {
afficherbarre();
form1.style.display="none";
}

trouvermotboutton.addEventListener("click", trouverlalettre)
function trouverlalettre(event) {
  validate();
  form1.style.display="none";

}
    
<!DOCTYPE html>
<html lang="fr">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Pendu</title>
</head>

<body>
    <h1>Jeux du pendu</h1>

    <h2>Veuillez entrer un mot</h2>
    <form id="chercherMot">
        <input type="text" id="motChercher"  minlength="5" maxlength="10" placeholder="Entrer un mot à trouver">
        <input type="button" id="boutoncherchermot" value="Trouver le  mot">
    </form>


    <form id="trouverleMot">
        <input type="text" id="trouverMot" maxlength="1" placeholder="Entrer une lettre">
        <button id="trouvermotboutton"> Inserer une lettre pour trouver le mot</button>
    </form>

    <div class="mot">
        <div id="champs"></div>
    </div>





    <div id="menu">
        <img src="img/1.png" id="image1">
    </div>






    <script src="script.js"></script>



</body>

</html>

How do I solve my issue with the forEach loop not working?

I keep getting an error saying .forEach is not a function I have a very similar function that runs just fine but I can’t figure out how to fix this forEach issue

function populateRepsDiv(repsArray) {
  removeChildren(senatorDiv)
  repsArray.forEach(representative => {
    const repFigure = document.createElement('figure')
    const repImg = document.createElement('img')
    const repCaption = document.createElement('figcaption')

    repImg.src = representative.imgURL
    repCaption.textContent = representative.name

    repFigure.appendChild(repImg)
    repFigure.appendChild(figCaption)
    senatorDiv.appendChild(repFigure)

    console.log(representative.name)
  })
}

How to update a div in a iframe?

I have an iframe that shows a page with a list of objects.

I have another page where the user can create new objects.
I would like to update the iframe content showing the list updated with the new object created.

controller.html

<html>
<script src="controller.js"></script>
<script src="iframe.js"></script>
     <iframe id="iFrame" style="border: 1px solid black" src="http://myurl:3000/iframe.html"  width="100%" height="300" 
      allowfullscreen sandbox="allow-scripts">
      </iframe>

<button onclick="obj.create()">Create </button>
</html>

controller.js

//function that is called after the user has created a new object

 getObjList(){
  let iframe  =  document.getElementById('iFrame');
  var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
  var obj_list
  var obj_message

if (iframeDocument) {
  obj_list = iframeDocument.getElementById('obj_list');
  obj_message = iframeDocument.getElementById('obj_message');
}
$.ajax({
    type: "GET",
    url: '/objects/iframe',
    success: function success(answer) {
      if (obj_list.innerHTML !== ""){
     
        $('#obj_list').html("")
      }
    
      if (typeof answer === 'object') {
        if (answer.message === 'ok'){
        if (answer.result.length > 0){
       
          obj_message.css('display', 'none');
          obj_list.css('display', 'block');

            for (let i=0; i<answer.result.length; i++){
                 obj_list.append(`
                <div class="card" style="width: 20rem;">
                <div class="card-body">
                  <h5 class="card-title">${answer.result[i].title}</h5>
                  <p class="card-text">Description: ${answer.result[i].desc}</p>

                </div>
              </div>`)
              }
        } else {
          obj_message.css('display', 'block');
          obj_list.css('display', 'none');
        }
        
        }
       console.log(answer)
      }
    },
    error: function error(error) {
      console.log('nope, it didnt work', error)
    }

  });

iframe.html

<html>
        <h2>LIST OF Obj - IFRAME </h2>
        
            <!---OBJ CONTAINER LIST-->
            <div id="obj_list">

            </div>
            <div id ="obj_message">
                <p>There have not been created any objects</p>
            </div>
    </div>
</html>

The problem I am having is that I am not able to update the content inside the iframe.
I get this error:
Blocked a frame with origin “xxxxxx” from accessing a cross-origin frame

Is there a way I can achieve the update of the content of an iframe?

The content of the iframe is a page I manage, that later has to be embedded in another website.

REACT- Redirection Link not working and applying filters on table

I have my table that displays all the id and title of my menu (1) (see menus.json). I want to add an hyperlink to my title but it doesn’t work:

{
    Header: "Title",
    // accessor: "title"
    accessor: (row) => row.title,
    // Link the content of my cell. NOT WORKING 
    Cell: ({ row }) => (
      <Link to={{ pathname: `/menu/${row.id}` }}>{row.title}</Link>
    )
}

By clicking on my title name,ex Menu1 (1), it will redirect me to a new page with a table that contains all the names of the menus that match my id_menu (2) .

Here a picture to get what I’m saying :
(1)

enter image description here

(2) When you click on Menu1 you should get (not working):

enter image description here

(same idea for the other menus)

Here the sandbox link: https://codesandbox.io/s/frosty-tree-ggwuty?

Thanks for your time.

Javascript exec() – a generic function that exec’s and returns stdout, stderr

I’m super new to JS and am struggling with a very basic task as I familiarize myself with it. I want to create a simple run(cmd) function that would receive a string with a command, and return an object containing stderr and stdout.

From what I found, I need to use exec or spawn, but I’m having trouble turning the examples online into a returning function:

const { exec } = require("child_process");

let run(cmd) = exec(cmd, (error, stdout, stderr) => {
    ret = {
        out: "",
        err: "",
        msg: ""
    }
    if (error) {
        ret.msg = error.message;
    }
    if (stderr) {
        ret.err = stderr;
    }
    ret.out = stdout;
    return ret;
});


out = run("ls -al");
console.log(out);

This doesn’t work and I’m probably making mistakes on multiple levels here

wait for finish function

I’ve this function with map, how can call only when finish?

 _.map(data,async function (el) {
        if(Number.parseInt(el) != NaN && (el != null) && !isNaN(el)){
            console.log('ID: ' + el)
            await scrapeDetails(el) // <--- need to wait finish and than go to next element in map
        }
    })

async function scrapeDetails(id){
// ... bla bla
}

Why React doesn’t pass “key” or “ref” props?

I’m in the process of learning React, and I found out that trying to pass “key” or even “ref” props to components does not work.

From a bit of research online I found that you can just pass a duplicate prop with the same data in it and it will work. But I couldn’t find why it isn’t allowed in the first place aside from answers stating that React uses these props internally.

A component is changing an uncontrolled input to be controlled

I am trying to do the discounted price logic

Discount price should have the default value of actual price , because 0% discount means the discount price is same as actual price.

when i do this i am getting this error, And it is changing randomly sometimes, and most of the time it is working fine .

import React, { Fragment, useState } from "react";
 
const App = () => {
  const [price, setPrice] = useState(0);
  const [discountPrice, setDiscountPrice] = useState(0);
  const [discountRate, setDiscountRate] = useState(0);

  const submitHandler = async () => {
    console.log("hello");
  };

  return (
    <>
      <Fragment>
        <div className="row">
          <div className="col-12 col-md-10">
            <Fragment>
              <div className="wrapper my-5">
                <form
                  onSubmit={submitHandler}
                >
                  <div className="form-group">
                    <label htmlFor="price_field">Price</label>
                    <input
                     
                      value={price}
                      onChange={(e) => {
                        setPrice(e.target.value);
                        setDiscountPrice(e.target.value);
                      }}
                    />
                  </div>
                  <div className="form-group">
                    <label htmlFor="discounted_price">Discounted Price</label>
                    <input
                      value={discountPrice}
                      onChange={(e) => {
                        setDiscountPrice(e.target.value);
                        setDiscountRate(
                          ((price - e.target.value) / price) * 100
                        );
                      }}
                    />
                  </div>
                  <div className="form-group">
                    <label htmlFor="discounted_rate">Discount Rate</label>
                    <div className="input-group mb-3">
                      <input
                       value={discountRate}
                        onChange={(e) => {
                          setDiscountRate(e.target.value);
                          setDiscountPrice(
                            price - (e.target.value / 100) * price
                          );
                        }}
                      />
                    </div>
                  </div>
                </form>
              </div>
              <></>
            </Fragment>
          </div>
        </div>
      </Fragment>
    </>
  );
};

export default App;

And how to actually see if the discount price value is empty ?

i tried

discountPrice == "" || discountPrice.trim() = "" || discountPrice== null
discountPrice.trim()===""

is not working, says trim is not a function

How to get a pdf or word of a react page?

I have a premade react app page with all the components already built but at the end of the page, I need a button so that when you click on it you either get all the fields of the page or just a screenshot of the actual page. How can I do this?

Getting success response but SMS not delivered [ AWS SNS ]

I try to send SMS(Text message) to a specific mobile number(MA : Morocco, FROM : Morocco) using AWS SNS service using nodeJs I get a success and the data looks like:

{“MessageID”:”ea4cf..”}

However, the SMS does not get delivered.

Here is the code:

router.post('/send-text', (req, res) => {

   var dynamoDBConfiguration = { 
    apiVersion: '2010-03-31',
     accessKeyId: 'A...',
     secretAccessKey: '...',
     region: 'eu-west-3'
    };


AWS.config.update(dynamoDBConfiguration);

// Create publish parameters
var params = {
  Message: req.body.message,
  PhoneNumber: '+' + req.body.number,

  MessageAttributes: {
    
      'AWS.SNS.SMS.SenderID': {
          'DataType': 'String',
          'StringValue': req.body.subject,
          
      }
  }
};
// Create promise and SNS service object
  var publishTextPromise = new AWS.SNS({ apiVersion: '2010-03-31' }).publish(params).promise();

  publishTextPromise.then(
    function (data) {
      res.end(JSON.stringify({ MessageID: data.MessageId }));
    }).catch(
      function (err) {
        res.end(JSON.stringify({ Error: err }));
      });

put uploaded file in a folder java vertx

i want to get file uploaded from frontend to backend java vertx and put the file in a folder with a giving name.

saveFile(){
      constfile=document.querySelector("input[type='file']").files[0]
  var myFormData = new FormData();
  myFormData.append('pictureFile', file);

  axios.post("http://localhost:8888/file/save",myFormData)
  .then(res=>console.log(res.data))
  .catch(err=>console.error(err))
}
<input type="file" accept=".csv">
<button @click="saveFile" type="submit">Save</button>

here is the backend verticle

  public void start(Promise<Void> startPromise) throws Exception {

    Router router=Router.router(vertx);

    router.route().handler(BodyHandler.create());
    router.route().handler(CorsHandler.create("http://localhost:8080")
      .allowedMethod(HttpMethod.POST));

    router.post("/file/save").handler(ctx->{
      Set<FileUpload> fileUploadSet = ctx.fileUploads();
      if (fileUploadSet == null || fileUploadSet.isEmpty()) {
        System.out.println("no file found");
      }else{
        for (FileUpload f : fileUploadSet) {
          vertx.fileSystem().createFile("src/main/resources/uploads/"+f.fileName(),res->{
            if(res.succeeded()){
             vertx.eventBus().request("file.save",f.fileName(),resp->{
                if(resp.succeeded()){                  ctx.response().setStatusCode(200).end((String) resp.result().body());
                }});
            }
          });
        }}
    });}