1

When using the following, I click on the submit button and it opens "domain.com/bhl.php?search=" and not passing the $_GET variable like I need.

<form action="bhl.php" method="GET">
    <input name="search" type="text" placeholder="Type here">
    <input type="submit" onclick="window.open('bhl.php?search=<?php echo $_GET['search'] ?>','targetWindow','toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=700, height=500'); return false;" />
</form>
4
  • remove onclick(), you can use $_GET in bh1.php. Commented Oct 21, 2015 at 18:14
  • Note that you are using quotation marks in a weird way. Just opening a bunch of them won't work as intended (since it will look like you are closing it). Commented Oct 21, 2015 at 18:14
  • @FirstOne There are no issue with quotation marks in that code. Commented Oct 21, 2015 at 18:17
  • @epascarello I might be mistaken, but I think I saw onclick='window.open('b.... Is it possible that a quick edition happened without showing the edit? Anyway, sorry about that, my bad... Commented Oct 21, 2015 at 18:21

2 Answers 2

2

It does not work because you are reading the value of the search parameter when the page has originally loaded. PHP does not run after the page load. You would need to set the value with JavaScript when the button is clicked.

<input type="submit" onclick="window.open('bhl.php?search=' + encodeURIComponent(this.form.search.value),'targetWindow','toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=700, height=500'); return false;" />
Sign up to request clarification or add additional context in comments.

Comments

0

You cannot pass a PHP variable through since theres no value when the page loads.

Try sending the value with javascript:

<form action="bhl.php" method="GET">
    <input id="search" type="text" placeholder="Type here">
    <input type="submit" onclick="window.open('bhl.php?search='+document.getElementById('search').value,'targetWindow','toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=700, height=500'); return false;" />
</form>

Although I'd define a function then just call that function, rather than using inline javascript.

Comments

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.