Using ngx-translate to display images

I would like to use ngx-translate inside my Angular app to display a language-specific image. In my case its a Logo which is displayed in different languages and styles depending on the used language.

I did already tried with

        <img style="width: 100px" [attr.src]="'branding.logo' | translate" alt="" class="src" />

Where branding.logo refers to a URL of the particular logo in the web.

But Chrome displays, that it couldn’t find the requested ressource at: ‘https://localhost:8100/branding.logo’.

What am I doing wrong?

How to set useReducer initial state using API response?

I’m new to React and trying to build an app with a cart feature where users can add robots to the cart. I’m using Context API to provide cart across the app and useReducer for states. The robots are being fetched from a server and load just fine. But I can’t seem to find a way to set the initial state of the reducer using fetched products. The state always returns an empty array for robots. How to solve this?

const CartProvider = ({ children }) => {
    const [robots, setRobots] = useState([]);

    useEffect(() => {
        fetch('http://localhost:8000/api/robots')
            .then(res => res.json())
            .then(data => setRobots(data?.data))
    }, [])

    const initialState = {
        robots: [...robots],
        cart: []
    }
    const [state, dispatch] = useReducer(cartReducer, initialState);

    return (
        <CartContext.Provider value={{ state, dispatch }}>
            {children}
        </CartContext.Provider>
    );
}
export default CartProvider;

Why Data is missing simultaneously when app script running & sometimes vanished from the whole spreadsheet & found no where

I have some issue where i had written a script that on the basis of a particular value of a row it should move to the specific sheet but dramatically it disappear simultaneously sometimes it work good & sometimes it vanished that row & can’t find anywhere in the spreadsheet where it had gone no one knows & even in some cases it automatically disappear or move the row by itself even if it is not defined to do so. Function is written below please help to rectify it.

function onEdit(e)
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Delhi Calls Asha");
  var values = sheet.getRange(1, 4, sheet.getLastRow(), 1).getValues();
  var moveRows = values.reduce(function(ar, e, i) {
    if (e[0] == "LG") ar.push(i + 1);
    return ar;
  }, []);
  var targetSheet = ss.getSheetByName("DELHI Calls Amit");
  moveRows.forEach(function(e) {
    sheet.getRange(e, 1, 1, sheet.getLastColumn()).moveTo(targetSheet.getRange(targetSheet.getLastRow() + 1, 1));
  });
  moveRows.reverse().forEach(function(e) {sheet.deleteRow(e)});
}


{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Delhi Calls Amit");
  var values = sheet.getRange(1, 22, sheet.getLastRow(), 1).getValues();
  var moveRows = values.reduce(function(ar, e, i) {
    if (e[0] == "Cancelled") ar.push(i + 1);
    return ar;
  }, []);
  var targetSheet = ss.getSheetByName("Happy Calling Delhi");
  moveRows.forEach(function(e) {
    sheet.getRange(e, 1, 1, sheet.getLastColumn()).moveTo(targetSheet.getRange(targetSheet.getLastRow() + 1, 1));
  });
  moveRows.reverse().forEach(function(e) {sheet.deleteRow(e)});
}

{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Delhi Calls Amit");
  var values = sheet.getRange(1, 22, sheet.getLastRow(), 1).getValues();
  var moveRows = values.reduce(function(ar, e, i) {
    if (e[0] == "Closed") ar.push(i + 1);
    return ar;
  }, []);
  var targetSheet = ss.getSheetByName("Happy Calling Delhi");
  moveRows.forEach(function(e) {
    sheet.getRange(e, 1, 1, sheet.getLastColumn()).moveTo(targetSheet.getRange(targetSheet.getLastRow() + 1, 1));
  });
  moveRows.reverse().forEach(function(e) {sheet.deleteRow(e)});

}
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Delhi Calls Asha");
  var values = sheet.getRange(1, 22, sheet.getLastRow(), 1).getValues();
  var moveRows = values.reduce(function(ar, e, i) {
    if (e[0] == "Cancelled") ar.push(i + 1);
    return ar;
  }, []);
  var targetSheet = ss.getSheetByName("Happy Calling Delhi");
  moveRows.forEach(function(e) {
    sheet.getRange(e, 1, 1, sheet.getLastColumn()).moveTo(targetSheet.getRange(targetSheet.getLastRow() + 1, 1));
  });
  moveRows.reverse().forEach(function(e) {sheet.deleteRow(e)});
}

{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet4 = ss.getSheetByName("Delhi Calls Asha");
  var values4 = sheet4.getRange(1, 22, sheet4.getLastRow(), 1).getValues();
  var moveRows4 = values4.reduce(function(ar, e, i) {
    if (e[0] == "Closed") ar.push(i + 1);
    return ar;
  }, []);
  var targetSheet4 = ss.getSheetByName("Happy Calling Delhi");
  moveRows4.forEach(function(e) {
    sheet4.getRange(e, 1, 1, sheet4.getLastColumn()).moveTo(targetSheet4.getRange(targetSheet4.getLastRow() + 1, 1));
  });
  moveRows4.reverse().forEach(function(e) {sheet4.deleteRow(e)});
}

{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet5 = ss.getSheetByName("MUMBAI Calls");
  var values5 = sheet5.getRange(1, 22, sheet5.getLastRow(), 1).getValues();
  var moveRows5 = values5.reduce(function(ar, e, i) {
    if (e[0] == "Cancelled") ar.push(i + 1);
    return ar;
  }, []);
  var targetSheet5 = ss.getSheetByName("Happy Calling Mumbai");
  moveRows5.forEach(function(e) {
    sheet5.getRange(e, 1, 1, sheet5.getLastColumn()).moveTo(targetSheet5.getRange(targetSheet5.getLastRow() + 1, 1));
  });
  moveRows5.reverse().forEach(function(e) {sheet5.deleteRow(e)});
}

{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet6 = ss.getSheetByName("MUMBAI Calls");
  var values6 = sheet6.getRange(1, 22, sheet6.getLastRow(), 1).getValues();
  var moveRows6 = values6.reduce(function(ar, e, i) {
    if (e[0] == "Closed") ar.push(i + 1);
    return ar;
  }, []);
  var targetSheet6 = ss.getSheetByName("Happy Calling Mumbai");
  moveRows6.forEach(function(e) {
    sheet6.getRange(e, 1, 1, sheet6.getLastColumn()).moveTo(targetSheet6.getRange(targetSheet6.getLastRow() + 1, 1));
  });
  moveRows6.reverse().forEach(function(e) {sheet6.deleteRow(e)});
}

{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet7 = ss.getSheetByName("Happy Calling Delhi");
  var values7 = sheet7.getRange(1, 31, sheet7.getLastRow(), 1).getValues();
  var moveRows7 = values7.reduce(function(ar, e, i) {
    if (e[0] == "satisfied") ar.push(i + 1);
    return ar;
  }, []);
  var targetSheet7 = ss.getSheetByName("Main Sheet Mix");
  moveRows7.forEach(function(e) {
    sheet7.getRange(e, 1, 1, sheet7.getLastColumn()).moveTo(targetSheet7.getRange(targetSheet7.getLastRow() + 1, 1));
  });
  moveRows7.reverse().forEach(function(e) {sheet7.deleteRow(e)});
}

{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet8 = ss.getSheetByName("Happy Calling Delhi");
  var values8 = sheet8.getRange(1, 31, sheet8.getLastRow(), 1).getValues();
  var moveRows8 = values8.reduce(function(ar, e, i) {
    if (e[0] == "SATISFIED") ar.push(i + 1);
    return ar;
  }, []);
  var targetSheet8 = ss.getSheetByName("Main Sheet Mix");
  moveRows8.forEach(function(e) {
    sheet8.getRange(e, 1, 1, sheet8.getLastColumn()).moveTo(targetSheet8.getRange(targetSheet8.getLastRow() + 1, 1));
  });
  moveRows8.reverse().forEach(function(e) {sheet8.deleteRow(e)});
}

{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet9 = ss.getSheetByName("Happy Calling Mumbai");
  var values9 = sheet9.getRange(1, 31, sheet9.getLastRow(), 1).getValues();
  var moveRows9 = values9.reduce(function(ar, e, i) {
    if (e[0] == "satisfied") ar.push(i + 1);
    return ar;
  }, []);
  var targetSheet9 = ss.getSheetByName("Main Sheet Mumbai");
  moveRows9.forEach(function(e) {
    sheet9.getRange(e, 1, 1, sheet9.getLastColumn()).moveTo(targetSheet9.getRange(targetSheet9.getLastRow() + 1, 1));
  });
  moveRows9.reverse().forEach(function(e) {sheet9.deleteRow(e)});
}

{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet10 = ss.getSheetByName("Main Sheet Mumbai");
  var values10 = sheet10.getRange(1, 58, sheet10.getLastRow(), 1).getValues();
  var moveRows10 = values10.reduce(function(ar, e, i) {
    if (e[0] == "Reopen") ar.push(i + 1);
    return ar;
  }, []);
  var targetSheet10 = ss.getSheetByName("MUMBAI Calls");
  moveRows10.forEach(function(e) {
    sheet10.getRange(e, 1, 1, sheet10.getLastColumn()).moveTo(targetSheet10.getRange(targetSheet10.getLastRow() + 1, 1));
  });
  moveRows10.reverse().forEach(function(e) {sheet10.deleteRow(e)});
}

{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet11 = ss.getSheetByName("Happy Calling Mumbai");
  var values11 = sheet11.getRange(1, 31, sheet11.getLastRow(), 1).getValues();
  var moveRows11 = values11.reduce(function(ar, e, i) {
    if (e[0] == "SATISFIED") ar.push(i + 1);
    return ar;
  }, []);
  var targetSheet11 = ss.getSheetByName("Main Sheet Mumbai");
  moveRows11.forEach(function(e) {
    sheet11.getRange(e, 1, 1, sheet11.getLastColumn()).moveTo(targetSheet11.getRange(targetSheet11.getLastRow() + 1, 1));
  });
  moveRows11.reverse().forEach(function(e) {sheet11.deleteRow(e)});
}

{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet12 = ss.getSheetByName("Main Sheet Mix");
  var values12 = sheet12.getRange(1, 58, sheet12.getLastRow(), 1).getValues();
  var moveRows12 = values12.reduce(function(ar, e, i) {
    if (e[0] == "Reopen") ar.push(i + 1);
    return ar;
  }, []);
  var targetSheet12 = ss.getSheetByName("DELHI Calls Asha");
  moveRows12.forEach(function(e) {
    sheet12.getRange(e, 1, 1, sheet12.getLastColumn()).moveTo(targetSheet12.getRange(targetSheet12.getLastRow() + 1, 1));
  });
  moveRows12.reverse().forEach(function(e) {sheet12.deleteRow(e)});
}

key charCode for virtual keyboard

I have the below code to allow the user input only numbers, this works in browser. But when I access on mobile I think I am not able to get the right key code. So what are the keycodes for the same. Isn’t same as the web.

  // block e char, dot, hiphen and spacebar
  if (event.key === 'e' || [46, 45, 32].includes(event.charCode)) {
    event.preventDefault();
  }else{
   // allow to input logic
}

What are the charCode for dot, hiphen and spacebar which will work for both web and mobile keypad ?

Any help is appreciated

Refreshing UI parts on each loop of an AJAX sync call

Okay, it might be a simple question, but so far I didn’t find anything helpful by searching, so I am giving it a try here.

I am using plain old javascript/jquery on asp.net core on some project I am working on.

I am currently performing some actions on some employees in a foreach loop.
For each employee I am calling synchronously via ajax an API.

What I want is the UI to be updated, showing the current employee being processed in a progress bar.

While on debug, the process seems to work fine, but during normal process, it seems that the UI thread is not updated, only after all the work has been done. As such, as soon as I start processing the employees, the screen is stuck and closes after the work has been done. No progress bar is shown.

I only managed to show the progress animation and the first employee using the below trick

$('#applyYes').click(function (e) {
   e.preventDefault();

   var year = $('#yearCombo').val();

   $('#applyInfo').hide();
   $('#applyLoad').show();
   $('#applyAction').prop('innerText', 'Calculating...');

   setTimeout(function () {

      var employeeIDs = multipleEmployees_Array();
      for (var i = 1; i <= employeeIDs.length; i++) {
         employeeID = employeeIDs[i - 1];
         applyAmount(employeeID, year); //1. Updates progress bar 2. Ajax sync call
      }

   }, 0);

})

As far as I understand the e.preventDefault seems to move the timeout function being processed after UI thread finishes.

What is the optimal way of achieving what I want?

PS: No external libraries if possible. I am working on an third-party platform, that makes it difficult to add external libraries (policies, permissions etc.)

Multiple audios interfering on the same web page in vue.js 2

I have a vue.js 2 frontend on which there are multiple chat bubbles. Each chat bubble is a vue component that has its own speaker subcomponent. When I click on the speaker, the goal is to read the audio corresponding to the text in the bubble.

The speaker is a component that is an HTML Media Element object, and is instantiated like that: this.audio = new Audio('path of the wav audio file on the CDN').

I have almost achieved this goal, but however, sometimes, when I click on the speaker of some bubble, the audio I hear is the one from another bubble. I don’t know how, but they are interfering in some way. How to solve that?

Owl Carousel just show 1 item

i have problem to show a owl carousel and its just show 1 item,
i want to show 2 or more item
this is my code

`function showNowPlay(data)
{
  
  nowplay.innerHTML = '<div class="home__carousel owl-carousel active" id="flixtv-hero">';

  data.forEach(movie => {
    data.splice(8);
    const {backdrop_path,title,release_date} = movie;
    const movieE3 = document.createElement('div');
    movieE3.classList.add('home__card');
    movieE3.innerHTML= '

my html

nowplay.appendChild(movieE3).owlCarousel({
});
});
}`

and html is

<div class="home__carousel owl-carousel" id="flixtv-hero">
        <div class="home__card">
            <a href="details.html">
                <img src="img/home/1.jpg" alt="">
            </a>
            <div>
                <h2>Money Plane</h2>
                <ul>
                    <li>Free</li>
                    <li>Action</li>
                    <li>2021</li>
                </ul>
            </div>
            <button class="home__add" type="button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M16,2H8A3,3,0,0,0,5,5V21a1,1,0,0,0,.5.87,1,1,0,0,0,1,0L12,18.69l5.5,3.18A1,1,0,0,0,18,22a1,1,0,0,0,.5-.13A1,1,0,0,0,19,21V5A3,3,0,0,0,16,2Zm1,17.27-4.5-2.6a1,1,0,0,0-1,0L7,19.27V5A1,1,0,0,1,8,4h8a1,1,0,0,1,1,1Z"/></svg></button>
            <span class="home__rating"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M22,9.67A1,1,0,0,0,21.14,9l-5.69-.83L12.9,3a1,1,0,0,0-1.8,0L8.55,8.16,2.86,9a1,1,0,0,0-.81.68,1,1,0,0,0,.25,1l4.13,4-1,5.68A1,1,0,0,0,6.9,21.44L12,18.77l5.1,2.67a.93.93,0,0,0,.46.12,1,1,0,0,0,.59-.19,1,1,0,0,0,.4-1l-1-5.68,4.13-4A1,1,0,0,0,22,9.67Zm-6.15,4a1,1,0,0,0-.29.88l.72,4.2-3.76-2a1.06,1.06,0,0,0-.94,0l-3.76,2,.72-4.2a1,1,0,0,0-.29-.88l-3-3,4.21-.61a1,1,0,0,0,.76-.55L12,5.7l1.88,3.82a1,1,0,0,0,.76.55l4.21.61Z"/></svg> 9.1</span>
        </div>

it just show 1 item,
how can i show 2-8 item ?
thanks

I am trying to send id to Controller with a dynamic button but it is not working

I’m trying to send the id of the object to the controller with the button. But it only does this for an item in the first row of the list. The button does not work for other items in the list. How can I solve the problem?

$(document).ready(function(){       
            $("#showTweet").click(function(){
         var tweetId = $(this).parent().attr('id');
        $.ajax({
        
        type: "GET",
        dataType: "json",
        url: "http://localhost:8020/showTweet?tweetId="+tweetId,
        success: function(result){
            var description = result.description;
            $('#tweetText').text(description);
            
             }
        });
    });
    
<table id="myTable" class="table table-striped">
                        <thead>
                            <tr>
                                <th>Kullanıcı</th>
                                <th>Oluşturulma Tarihi</th>
                                <th>Seçenekler</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr th:each="unapprovedTweets: ${unapprovedTweets}">
                                <td th:text="${unapprovedTweets.creative}"></td>
                                <td th:text="${unapprovedTweets.create_date}"></td>
                                <td>
                                
                                    <div th:id="${unapprovedTweets.id}"
                                        style="width: 0px; height: 0px; display: contents;">
                                        <a id="showTweet" class="btn btn-warning">Tweeti Gör</a>
                                        
                                        
                                    </div> <a th:href="@{'/sendTweet/' + ${unapprovedTweets.id}}"
                                    class="btn btn-primary" style="width: 90px; margin-left: 5px;">Onayla</a>
                                    <a th:href="@{'/refuseTweet/' + ${unapprovedTweets.id}}"
                                    class="btn btn-danger" style="width: 90px; margin-left: 5px;">Reddet</a>


                                </td>

                            </tr>
                        </tbody>
                    </table>

fetch http request succeeds in Chrome and Firefox but fails in Safari

If we run the following code in safari it fails saying “failed to load resource: cannot parse response”

fetch('https://mycompanyname/service/contracts-api/operatingMode', {
  method: "GET",
  headers: new Headers({
    'Authorization': 'Basic VGVzdFVzZXIxOlRFU1QhdXNlcjE=',
    'X-mycompanyname-ContractsServer': 'someurl'
  })
}

safari inspect element preview

safari inspect element headers
But if we run the same code in Chrome or Firefox, it succeeds (in the same mac computer).

Is there any quirk in Safari fetch request that I am not considering?

event not trigger on first click parent Childs

I am creating hierarchy relations list with parent Childs and sub-childs if i checked parent then all Childs with checked but i clicked on Childs then sub-childs will be checked. everything is working fine but its work on second click not working on first click.
here is my fiddle example.
fiddle link here http://jsfiddle.net/fahadsheikh/qdkwy0s7/8/

function changeCategoryStatus(_this, id) {

var main = document.querySelector(".main-checkbox"+id);
var children = document.querySelectorAll(".sub-checkbox"+id);

function toggleCheck() {

  var array=[];
  children.forEach(child => {
    if($(this).prop("checked") == true){
        child.checked = child.checked = true
    }
    else if($(this).prop("checked") == false){
        child.checked = child.checked = false
    }

    
    array.push(child.value);
    
  })

  return array;
}

if(main){
    main.addEventListener("click", toggleCheck);
}

//for sub-parent category

var sub_parent = document.querySelector(".sub-parent"+id);
var sub_children = document.querySelectorAll(".sub-checkbox"+id);

function toggleCheck() {

  var array=[];
  sub_children.forEach(child => {
    if($(this).prop("checked") == true){
        child.checked = child.checked = true
    }
    else if($(this).prop("checked") == false){
        child.checked = child.checked = false
    }

    
    array.push(child.value);
    
  })

  return array;
}

if(sub_parent){
    sub_parent.addEventListener("click", toggleCheck);
}

 
    var status = $(_this).prop('checked') == true ? 'active' : 'inactive';
    $.ajax({
        type: 'POST',
        url:"{{url('admin/categories-status')}}",
        data: {
            id: id,
            status: status,
            _token: "{{ csrf_token() }}"
        },
        success: function (result) {
        $("#status-success").show();
        $("#status-success").html(result.success);
        setTimeout(function() {
            $("#status-success").hide()
        }, 3000);
        }
    });

}
body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#banner-message {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  font-size: 25px;
  text-align: center;
  transition: all 0.2s;
  margin: 0 auto;
  width: 300px;
}

button {
  background: #0084ff;
  border: none;
  border-radius: 5px;
  padding: 8px 14px;
  font-size: 15px;
  color: #fff;
}

#banner-message.alt {
  background: #0084ff;
  color: #fff;
  margin-top: 40px;
  width: 200px;
}

#banner-message.alt button {
  background: #fff;
  color: #000;
}
<div class="sortable">
   <div class="group-caption">
       <li class="main-parent category-sortable main-item" data-parent="4" data-position="4" data-newposition="1">second room 
                <span class="buttons-align">
                <label class="switch">
                    <input class="main-checkbox4" type="checkbox" id="user-4"
                        onclick="changeCategoryStatus(event.target, 4);"
                        >
                    <span class="slider round"></span>
                </label>
                
                </span>
                <div class="move" id="item-move" ><i class="fa fa-bars" aria-hidden="true"></i></div></li>
                <ul class="group-items group-items-parent">
                                                                                <li class="group-item-parent category-sortable" data-parent="5" data-position="1" data-newposition="1">second-child room 
                    <span class="buttons-align">
                    <label class="switch">
                        <input class="sub-checkbox4 sub-parent4" type="checkbox" id="user-5"
                            onclick="changeCategoryStatus(event.target, 5);"
                            >
                        <span class="slider round"></span>
                    </label>
                    </span>
                    <div class="move"><i class="fa fa-bars" aria-hidden="true"></i></div></li>

                                                                                <ul class="group-items-child">
                                                                    <li class="group-item-child category-sortable" data-parent="6" data-position="1" data-newposition="0">second subchild
                                    <span class="buttons-align">
                                    <label class="switch">
                                        <input class="sub-checkbox4" type="checkbox" id="user-6"
                                            onclick="changeCategoryStatus(event.target, 6);"
                                            >
                                        <span class="slider round"></span>
                                    </label>
                                    </span>
                                    <div class="move"><i class="fa fa-bars" aria-hidden="true"></i></div></li>
                                                                                            </ul>
                                                                                                            </ul>
                </div>
                                                                                <div class="group-caption">
                <li class="main-parent category-sortable main-item" data-parent="7" data-position="4" data-newposition="2">third-room 
                <span class="buttons-align">
                <label class="switch">
                    <input class="main-checkbox7" type="checkbox" id="user-7"
                        onclick="changeCategoryStatus(event.target, 7);"
                        >
                    <span class="slider round"></span>
                </label>
                
                </span>
                <div class="move" id="item-move" ><i class="fa fa-bars" aria-hidden="true"></i></div></li>
                <ul class="group-items group-items-parent">
                                                                                <li class="group-item-parent category-sortable" data-parent="9" data-position="1" data-newposition="1">third-child 
                    <span class="buttons-align">
                    <label class="switch">
                        <input class="sub-checkbox7 sub-parent7" type="checkbox" id="user-9"
                            onclick="changeCategoryStatus(event.target, 9);"
                            >
                        <span class="slider round"></span>
                    </label>
                    </span>
                    <div class="move"><i class="fa fa-bars" aria-hidden="true"></i></div></li>

                                                                                <ul class="group-items-child">
                                                                    <li class="group-item-child category-sortable" data-parent="10" data-position="1" data-newposition="0">third-subchild
                                    <span class="buttons-align">
                                    <label class="switch">
                                        <input class="sub-checkbox7" type="checkbox" id="user-10"
                                            onclick="changeCategoryStatus(event.target, 10);"
                                            >
                                        <span class="slider round"></span>
                                    </label>
                                    </span>
                                    <div class="move"><i class="fa fa-bars" aria-hidden="true"></i></div></li>
                                                                                            </ul>
                                                                                                            </ul>
                </div>
                                                                
            </div>

thanks for help.

JS add event handler using for loop, passing self as parameter not working

I am wondering why the statement “let im = _imgs[i];” is indispensable in this situation.
Essentially, the _imgs are an array of image elements. But if I add the eventhandlers by _imgs[i].addEventListener("click", function(){clickImage(_imgs[i]);}, false);, it won’t work.

Can anyone explain why? Thanks a lot!

function init()
{
    _imgs = document.querySelectorAll("#block2 img");
    console.log(_imgs.length);
    _clicked = new Object();
    for(var i = 0; i < _imgs.length; i++)    
    {      
        let im = _imgs[i];
        _imgs[i].addEventListener("click", function(){clickImage(im);}, false);
        _clicked[_imgs[i].id] = 0;
    }
    console.log("hi");
}

How to add a notification text in an HTML link and remove when clicked?

I’m creating a website which has daily news updates with URL links. I need to add a NEW! text on top of the link and once the user has visited it, need to remove the text. I searched for it everywhere what this feature is called and also went through anchor tag attribute in CSS i.e. a:visited {}, but it’s only CSS, how can I use for the above scenario?

Also if there’s any other way to deal with newly added links and after certain time, the NEW! text is gone, please let me know, I’m unable to find any resources online. Thanks.

html form not grabbing correct variables from survey

I am building a survey form that gathers information from students, using HTML (open to using javascript too) and have found several examples online but none seem to be working. The survey form is currently just selecting these:

enter image description here

The survey should be selecting all options (first name, last name, living place, college choices, major, campus visit), and I don’t know how to fix this.

This is the survey and the code:

enter image description here

 <h3> Senior Survey </h3>
    <div class="w3-container">

      <script type="text/javascript">
        console.log("Prospective student form is about to be displayed.");
      </script>

      <form method="post" action="mailto:[email protected]" method="GET" enctype="text/plain" name="seniorsurvey">
        <table class="w3-table w3-blue" id="second-gradient">
          
          <tr>
            <td style="text-align: center";> 
            <p><b> Please enter your first and last names. </b></p>
            <input type="text" id="firstname" maxlength="60" placeholder="First Name:"/> 
            <input type="text" id="lastname" maxlength="60" placeholder="Last Name:"/>  
            </td>
          </tr>

          <tr>
            <td style="text-align: center";> 
              <p><b> Where do you live? </b></p>
              <input type="radio" id="peru" name="radiobutton" value="Peru">
              <label for="peru">Peru</label>

              <input type="radio" id="southamerica" name="radiobutton" value="SA">
              <label for="southamerica">South America</label>

              <input type="radio" id="unitedstates" name="radiobutton" value="USA">
              <label for="unitedstates">United States</label> 
            </td>
          </tr>

          <tr>
            <td>
              <fieldset style="text-align: center";>
                <p><b> What were your other top college choices? </b></p>
                <input type="checkbox" id="bentley" name="uni">
                <label for="bentley">Bentley U.</label>

                <input type="checkbox" id="brandeis" name="uni">
                <label for="brandeis">Brandeis U.</label>
                
                <input type="checkbox" id="boston" name="uni">
                <label for="boston">Boston U.</label>
                
                <input type="checkbox" id="babson" name="uni">
                <label for="babson">Babson U.</label>     
                
                <input type="checkbox" id="northeastern" name="uni">
                <label for="northeastern">Northeastern U.</label>               
              </fieldset>
            </td>
          </tr>

          <tr>
            <td style="text-align: center";> 
              <p><b> What is your prospective major? </b></p>
              <select name="majors" id="majors">
                <option value="un">undecided</option>
                <option value="cis">Computer Information Systems</option>
                <option value="fi">Finance</option>
                <option value="acc">Accounting</option>
                <option value="ci">Creative Industries</option>
                <option value="mkt">Marketing</option>
              </select>
              <br>
            </td>
          </tr>

          <tr>
            <td style="text-align: center";> 
              <p><b> When do you plan to visit campus? </b></p>
              <input type="date" id="start" name="visit-start" value="2021-10-25" min="2021-10-25" max="2030-12-31">
              <br><br>
            </td>
          </tr>

          <tr>
            <td style="text-align: center";> 
              <button type="submit" value="Submit College Info"> Submit </button>
              <button type="reset" value="Clear College Info"> Clear  </button>
              <br><br>
            </td>
          </tr>

        </table>
      </form>      

    </div>

Promise trouble! How can I write this in such a way that it waits for the end?

Trying to write this in a way that it will wait for the db operations to complete. Possible?

function addFriendsToSession(session, sessionId) {
    const friends = [];

    const incoming = session.users.forEach(async user => {
        console.log('user', user);
        await db
            .collection('users/' + user + '/settings')
            .doc(user)
            .get()
            .then(doc => {
                if (doc.exists) {
                    const returnObj = doc.data();
                    return returnObj.friends ? returnObj.friends : [];
                } else {
                    return [];
                }
            });
    });
    friends.push(incoming);
    return friends;
}