How can I get a returned object from this function?

his function return an object, i’m just not get value out of this:

function callObject(){
    if(validateInput.test(monthAport)){
      setInputErr(false)
      setResult(true)
      let filtered = simulate.filter(item =>
        item.tipoIndexacao == typeIn && item.tipoRendimento == typeYi )

        return filtered
    }else{
      setInputErr(true)
      }
  }

tks

Dynamic inline importing raw SVG in Vue.js & Vite

So I am trying to import SVG as string into my Vue component using inline import on Vite as follows

<script>
const getSvgIcon = async (name) => {
  const module = await import(`../icons/${name}.svg?raw`)
  return module.default
}

export default {
  props: {
    name: String,
  },
  data() {
    return {
      svg: null,
    }
  },
  watch: {
    name: {
      async handler(name) {
        this.svg = await getSvgIcon(name)
      },
      immediate: true,
    },
  },
}
</script>

<template>
  <div v-html="svg"></div>
</template>

This works just fine when running on npm run dev mode.

However, the issue happens when running npm run build, I end up getting Error: Unknown variable dynamic import apparently because I’m using ?raw suffix.

Is there a solution or is this a handicap by Vite as of now?

Converting classic asp to javascript: How to write or make returned string (json+ld) visible in header of webpage using javascript?

I have this Classic Asp code in header section of webpages:

<%
dim url, param, avgrate, votes, p, s
 url = "https://au2mailer.com/api/a2m-getschemaorg.asp"
 param = "?apikey=fe9fc289c3ff0af142b6d3bead98a923"
 Set HttpReq = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
 HttpReq.SetOption(2) = 8192
 HttpReq.open "GET", url & param, false
 HttpReq.setRequestHeader "Content-Type", "application/json"
 HttpReq.Send()
 if (HttpReq.status = 200) Then
   response.write(HttpReq.responseText)
 end if
%>

and it works and is accepted by Google Schema Markup Validator.
Page to check https://carmagic.dk/online-bil-forretning-hvordan.asp
(Danish website)
I need to change the code so that it works whether the page is html, asp, aspx or php and my idea was to change it to javascript.
I have tried this javascript in header section

  <script>
      var request = new XMLHttpRequest();
        request.open('GET', 'https://au2mailer.com/api/a2m-getschemaorg.asp?apikey=fe9fc289c3ff0af142b6d3bead98a923');
        request.send();
        request.onload = ()=>{
          var receivedDom = new DOMParser().parseFromString(request.response, "text/html");
          var jsonstr = receivedDom.body.innerText;
          document.write(jsonstr);
        }
  </script>

The code execute but it does not work as the classic asp code!
Is my classic asp code not possible in javascript?

Thank you in advance and nice weekend

Michael Fiil

I cannot send form by using sweetalert 2

I read a lot of posts on this but nothing work on my side

I have the follow php code:

<?

if( isset($_POST['btn-login']) ) {    
$mails = new PHPMailer;
$content = "xxxx";
$mails->IsSMTP();
$mails->send();
}

?>


<form name="form1" id="form1" class="form1" method="post">
<input class="form-control"  name="oggetto" id="oggetto" required placeholder="Oggetto"  >
<input class="btn-login" type="submit" name="submit" id="btn-submit" value="Invia"/>
</form>

with this script:

<script>

  $('#btn-submit').on('click',function(e){
                e.preventDefault();
                var form = $('.form1');
                console.log("hello");
                swal.fire({
                    title: "Inviare il msg?",
                    icon: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "Si",
                }).then(function (result){
                    if(result.value === true){
                    console.log(form);
                    $('.form1').submit();
                  }
                });
            });
</script>

i can see the popup with sweet alert but when i click on the submit button the form doesn’t work.
Pls don’t consider parameters of PHPMailer (that are just to understand the structure)

JFiddle example is here

Any help on this?
thanks in advance

reduce two functions to one, simplify 2 functions into one with javsacript

Hi guys, any idea how to put these 2 functions together and call them separately? Thank you

//Function box + 
function boxMore(box,increment){
var numBox=casella.substring(1,3);
var letterBox=casella.substring(0,1);
var numnewBox=parseInt(numBox)+increment;
return letterBox+numnewBox;
}

//Function box -
function boxLess(box,increment){
var numBox=box.substring(1,3);
var letterBox=box.substring(0,1);
var numnewBox=parseInt(numBox)-increment;
return letterBox+numnewBox;
}

Javascript ajax how to change the file name before uploading file to server

I am trying to upload a file but i don’t understand how i can change the file name before uploading

html part

<form class="float-sm-right"method="POST" enctype="multipart/form-data" id="fileUploadForm">
<div class="uploadbutton"><input class="hide_file" id="myfilefield" onchange="this.form.submit()" type="file" name="files" multiple>Upload</div>
</form>

Script part

    document.getElementById('myfilefield').onchange = function() {
        event.preventDefault();
        var form = $('#fileUploadForm')[0];
        var data = new FormData(form);
        $("#btnSubmit").prop("disabled", true);
        $.ajax({
            type: "POST",
            enctype: 'multipart/form-data',
            url: "<?= Pterodactyl::serverUploadFile();?>",
            data: data,
            processData: false,
            contentType: false,
            cache: false,
            timeout: 600000,
            success: function (data) {
                $("#result").text(data);
                console.log("SUCCESS : ", data);
                $("#btnSubmit").prop("disabled", false);
                window.location.reload();
            },
            error: function (e) {
                $("#result").text(e.responseText);
                console.log("ERROR : ", e);
                $("#btnSubmit").prop("disabled", false);
            }
        });
    };

I dont get how i can change the filename before uploading.

TRANSFER DATA FROM MY TABLE EXCEL TO A USERS IN HTML

I AM A DEVELOPPER BEGGINER I HAD A WEBSITE TO CREATE US A PLATEFORM FOR STUDENTS AND EMPLOYEES
I HAD ISSUES I CAN’T FIND THEM FIRST OF ALL I AM CREATE A FUNCTION THAT UPLOAD A FILES ONLY FOR XLSX , XLS WHICH IT EXCEL FILES ONLY US I CREATE THE WEBSITE FOR STUDENT AND EMPLOYEES I WANNA SHARE TRANSFER EVERY MARK FOR EVERY STUDENTS. I HAD CREATE THE WEBSITE WITH HTML PHP CSS JAVASCRIPT AND PHP ALSO MY SQL AND I MAKE THE ACCESS FOR STUDENT NOT LIKE EMPLOYEES ANY HAD REGISTRATION TABLE IN MYSQL… I DON’T HAVE ANY ISSUES US UPLOAD A EXCEL FILE AND SHARE OR DISPLAY MARKS FOR EACH STUDENT I HAVE ….
I BUILD THIS WEBSITE FOR ME US AM EMPLOYEER AND FOR THE EMPLOYEERS WHO’S WORKING WITH ME AND FOR MY STUDENTS , I ALSO HAVE MANY CLASSES

Apps Script HTML Code Failing for Shared Users

Apologies for the beginner question.

I have an app script that creates a user popup selection menu when my Google Sheet is edited. The selection menu was created in HTML. This works exactly as intended when I edit the spreadsheet from my own account. However, when a shared user does the same thing, withFailureHandler gets executed.

Here’s my Code.gs:

function doGet(e){
  
  var html = HtmlService.createHtmlOutputFromFile('Index')
  
      .setWidth(250)
      .setHeight(200);
  SpreadsheetApp.getUi() // Or DocumentApp or SlidesApp or FormApp.
      .showModalDialog(html, 'Animal');  
}
      
function displayMessage(selection){
  
SpreadsheetApp.getUi().alert("Your selection was: "+selection);

}

And here’s the Index.html:

 <form>
 Select animal:
 <br><br>
 <div class="custom-select">
 <select id="myList" onchange="selectionMade()">
   <option>Selection Option</option>
   <option>Cat</option>
   <option>Dog</option>  
   <option>Horse</option>
 
 </select>

<script>

function selectionMade(selection) {
 
  var mylist = document.getElementById("myList");
  var selection = mylist.options[mylist.selectedIndex].text;
  google.script.run
     .withSuccessHandler(function(data,element){window.alert("executed");})
     .withFailureHandler(function(msg,element){window.alert("failed"); })
     .displayMessage(selection);
}

</script>

I’m looking for the script to return the selection value to the spreadsheet for shared users the same one is does when I use it from my account.

Thanks in advance.

Log click event on html link using Amplitude SDK

I’m trying to log an event when a <a> link is clicked before navigating to the final destination, this is what I have so far:

<a href="/account" data-event-type="select_account">My account</a>
document.querySelectorAll('a[data-event-type]').forEach(link => 
  link.addEventListener('click', function onLoggableActionClicked(ev) {
    ev.preventDefault();

    amplitude.getInstance().logEvent(link.getAttribute('data-event-type'));
                  
    window.location.href = link.href;
  })
)

The event fires perfectly but the event doesn’t get logged, maybe because the request is ended when the browser is redirected?

I tried using a callback but waiting for it makes the navigation impossible:

function onLoggableActionClicked(ev) {
  ev.preventDefault();

  amplitude.getInstance().logEvent(link.getAttribute('data-event-type'), null, function() { window.location.href = link.href });
})

How can I log events for outbound links?

JS shows both content spots with if and if else

I have following code

  if (K.API.Core.runWhenElementPresent('.has-flag', function () {
        var KamTestTemplate= '<div id="KamNotice"<span>text</span></div>';
        document.querySelector('#product-transaction-area').insertAdjacentHTML('afterbegin', KamNoticeTemplate)
    }));
    
    else if (K.API.Core.runWhenElementPresent('.product-media', function () {
        var KamTestTemplate= '<div id="KamNotice"<span>text</span></div>';
        document.querySelector('.product-media').insertAdjacentHTML('afterbegin', KamNoticeTemplate)
}));
    

I want that if the first div has-flag, the content should be shown in the transaction-area, and if the div has product-media, it should be shown within the product-media content box, but something is wrong with my code i get the content in both boxes, not in one.

Why does JQUERY not work with the IntersectionObserver when get by class?

Here is my code:

var TestObserver = new IntersectionObserver(changes => {
        changes.forEach(change => {
            //some logic
        })       
    }, { thresholds: 1 });    
    $(".Test").each(function () {        
        TestObserver.observe($(this));
    });    

After the code ran, Chrome reports this error:

Uncaught TypeError: Failed to execute 'observe' on 'IntersectionObserver': parameter 1 is not of type 'Element'.

What’s wrong with my code? And how can I solve this? Thank you.

How to convert recursion to loop?

I need convert this code to loops , but i have no idea how .

let object = { x:250 , a : 5 , b : 5 , c : {ac: 5 , acd : 10}};

 let objectPropertiesSum = object => {
     let sum = 0;
     for (const value of Object.values(object)) {
       if (typeof(value) === "number") {
         sum += value;
       }
       else if (typeof(value) === "object") {
         sum += objectPropertiesSum(value);
       }
     }
     return sum;
   };
console.log(objectPropertiesSum(object));

Im trying to navigate to my shipping page but i keep getting this error

This is the error message

react-dom.development.js:11340 Uncaught TypeError: Cannot read properties of undefined (reading 'search')
at Login (Login.js:21:1)
at renderWithHooks (react-dom.development.js:14985:1)
at mountIndeterminateComponent (react-dom.development.js:17811:1)
at beginWork (react-dom.development.js:19049:1)
at HTMLUnknownElement.callCallback (react-dom.development.js:3945:1)
at Object.invokeGuardedCallbackDev (react-dom.development.js:3994:1)
at invokeGuardedCallback (react-dom.development.js:4056:1)
at beginWork$1 (react-dom.development.js:23964:1)
at performUnitOfWork (react-dom.development.js:22776:1)
at workLoopSync (react-dom.development.js:22707:1)

This is my code

my Login.js

const Login = ({ history, location }) => {

const [email, setEmail] = useState('');
const [password, setPassword] = useState('');

const alert = useAlert();
const dispatch = useDispatch();

const { isAuthenticated, error, loading } = useSelector(state => state.auth);

const redirect = location.search ? location.search.split('=')[1] : '/'

const navigate = useNavigate();
// navigate('/')



useEffect(() => {

    if (isAuthenticated) {
        navigate(redirect)
    }

    if (error) {
        alert.error(error);
        dispatch(clearErrors());
    }

}, [dispatch, alert, isAuthenticated, error, navigate, redirect])


const submitHandler = (e) => {
    e.preventDefault();
    dispatch(login(email, password))
}

return ()} export default Login

the error seems to be coming from my “location.search” because in my vscode that part is line 21. Has there been any recent change in documentation?