0

I want to create a page with about 300 textboxs from a foreach loop. I am able to write links into the textboxes, but i can't read textboxes array. Buttons are not working. How to submit these links via buttons?

echo "<form><input style='width:1000px' type='text' name='link[]' value='https://example.com/api/user_api.php?request=SellItem&amount=" . $number . "&featured=0&classid=" . $item["classid"] . "&instanceid=" . $item["instanceid"] . "&key=xxx'". "<br>";
echo "<input name='Launchlink[]' type='button' value='Send' onclick='location.href=this.form.elements['link[]'].value'></form>'";
2
  • type='submit' and get rid of of onclick Commented Sep 1, 2015 at 21:39
  • thanks but doesn't work. Commented Sep 1, 2015 at 21:48

1 Answer 1

1

In light of your comments

var links = <?=json_encode($the_link_array)?>;
function open_all_of_the_links(){
    for (var i = 0; i < links.length; ++i) {
        window.open(links[i], "_blank");
    }
}
document.getElementById("theButton").addEventListener("click", open_all_of_the_links);

And then you can have anything with an ID of "theButton" and that'll register an event on it and should open all of the URLs in new tabs.

<span id="theButton">Click here to make all of your dreams come true</span>
Sign up to request clarification or add additional context in comments.

5 Comments

Something wrong. it adds the link at the end of my current page. Like that: localhost/test.php?link%5B%5D={link}
@ozbackgammon what do you want it to do, then? It's not terribly clear from your question. I mean, that's submitting the link as a member of an array called links, which is what it looked like you wanted.
i want to open new tab these links when i click button. Thats it.
Thank you very much. It should work. But my problem is something else now. "Uncaught ReferenceError: links is not defined". I can't define name='links[]' array. Do you know why?
'links' would be the name of the array of URLs that I thought you had handy. If it's a PHP array, you can json_encode it into the output. I'll add that to the example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.