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.

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.

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

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?

Angular – ngIf condition displays both the data on Initial render

In my Angular project where I get data from API and display on frontend. I am using ngIf to display data, if no data is available then elseNotDone is displayed.

The problem I am facing is when component reloads, I first see No Data available for few milliseconds and then data is displayed

How can I make sure else condition is not displayed on initial render?

<section *ngIf="data!== undefined && data.length > 0; else elseNotDone">
  <h2>Amazon Data</h2>
  <div>
  // display data from API
  </div>
</section>
  <ng-template #elseNotDone>
  No Data available
  </ng-template>

Make new same form on next last field

I created the field on form html with press enter instead of tab, i want to make automatic create new same form when its enter in last field form

my problem : the form automatic created starting with the second field, and the form always makes a multiple of 2 forms

expetation : created new same form once the user presses enter in the last field, and its just always 1 form only so on, and the select form follow the next new field form too.

Script

        var display = document.getElementById("area")
        function tabE(obj, e) {
            var e = (typeof event != 'undefined') ? window.event : e;
            if (e.keyCode == 13) {
                var ele = document.forms[0].elements;
                for (var i = 0; i < ele.length; i++) {
                    var q = (i == ele.length - 1) ? 0 : i + 1;
                    if (obj == ele[i]) {
                        ele[q].focus();
                        break
                    }                  
                    display.insertAdjacentHTML('beforeend', 
                        `<form method="" action="">            
                            <table>
                                <td>1<br><input type="text" onkeypress="return tabE(this,event)"></td>
                                <td>2<br><input type="text" onkeypress="return tabE(this,event)"></td>
                                <td>3<br><input type="text" onkeypress="return tabE(this,event)"></td>
                                <td>4<br><input type="text" onkeypress="return tabE(this,event)"></td>
                <td>5<br><input type="text" onkeypress="return tabE(this,event)"></td>
                <td>6<br><input type="text" onkeypress="return tabE(this,event)"></td>                
                <td>7<br><input type="text" onkeypress="return tabE(this,event)"></td>
                            </table>           
                        </form>`);
                }
                return false;
            }   
        }
<!DOCTYPE html>
<html>
<head>
</head>

<body onkeydown="javascript:if(window.event.keyCode == 13) window.event.keyCode = 9;">
    <div class="area" id="area">
        <form method="" action="">
               
            <table>
                <td>1<br><input type="text" onkeypress="return tabE(this,event)"></td>
                <td>2<br><input type="text" onkeypress="return tabE(this,event)"></td>
                <td>3<br><input type="text" onkeypress="return tabE(this,event)"></td>
                <td>4<br><input type="text" onkeypress="return tabE(this,event)"></td>
                <td>5<br><input type="text" onkeypress="return tabE(this,event)"></td>
                <td>6<br><input type="text" onkeypress="return tabE(this,event)"></td>                
                <td>7<br><input type="text" onkeypress="return tabE(this,event)"></td>

            </table>           

        </form>
    </div>
 </body>
 </html>