0

there is a problem with my code I try to split array values to single individual strings that contains part of links.

I tried with dele.join() , but still the output is single string with coma separation

$(function () {

            $("#selectedel").click(function () {
                var dele =[]; // Array look like this  ["/delete.php?id=1","/delete.php?id=2","/delete.php?id=3"]
                $.each($("input:checkbox[name='dele']:checked"), function () {
                    dele.push($(this).val());

                });
                console.log(dele.toString());
                console.log(dele.join(","));
            })


        });

output of this code is

/delete.php?id=1,/delete.php?id=2,/delete.php?id=3

The output that i want is

/delete.php?id=1
/delete.php?id=2
/delete.php?id=3

Which in the end i want to open this links with window.open() at once .

Thank you in advance

6
  • 1
    What about .join('\n')? Commented Jan 26, 2022 at 13:55
  • "Which in the end i want to open this links with window.open() at once" - window.open() only opens one URL per call. Commented Jan 26, 2022 at 13:56
  • @Andreas yes but if i separate them in individual strings ? Commented Jan 26, 2022 at 13:58
  • @evolutionxbox is still 1 string , just on new line Commented Jan 26, 2022 at 13:59
  • if you want to open multiple link with window.open(), you need to have multiple calls. the easiest way would be toput the instruction into your each loop Commented Jan 26, 2022 at 14:01

1 Answer 1

1

Try this one

["/delete.php?id=1", "/delete.php?id=2", "/delete.php?id=3"].map((url) => {
  const xhr = new XMLHttpRequest();
  xhr.onreadystatechange = function() {};
  xhr.open('GET', url);
  xhr.send();
});
Sign up to request clarification or add additional context in comments.

5 Comments

still opens just one
This sounds like an answer then stackoverflow.com/questions/53593619/…
What is the purpose of opening 3 links? Maybe its better for you to receive the content in ajax request and render on the same window?
the purpose is deleting rows from a csv file , it was just single before with anchor <a href="delete.php?id=i>X</a>" now i want to can multiple choices with a checkbox ... that i try to do yes .. it will be better with ajax but i dont know how to do it
I edited the answer, Its very simple and fast example, Try search about XHR in js, or fetch in ts/react/angular etc... to learn more and develop it further to match your requirement

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.