Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form that onclick passes the result (waybillno) over to the popup page as a URL with the id selectors. It only passes the result on the 2nd click and sends an empty selector result with the URL on the first click, which tells me the form is being passed before the variable is set. I have tried moving the code up to force the variable to be "created earlier" but is has not helped. Any help appreciated.
Here is the code:-

<!DOCTYPE html>
<html lang="en">

<head>

</head>
<div class="container">

    <div class="row margin-10">
        <div class="col-md-4">
            <h4 class="orange-grad"><span class="white">WAYBILL UPDATES</span></h4>
            <form class="form-horizontal" role="form" action="popuptest.php" method="get">
                <input type="text" name="waybillno" class="search-query form-control col-md-6" placeholder="Waybill #">
                <button onclick="myFunction()">Go Now</button>

            </form>
        </div>
    </div>
</div>
<?php $id=$_GET['waybillno'];
echo $id;?>

    <script>
        function myFunction() {

            var myWindow = window.open("popuptest1.php?id=<?php echo $id=$_GET['waybillno'];?>", " ", "width = 1200, height = 400, top = 100, left = 300 ");
        }
    </script>

</html>


What I have tried:

Moving the myFunction script around to see if the order of code makes a difference.
I have spent two full days on thi, researching but with no luck.
Posted
Updated 23-May-18 4:45am

It would seem that the value, on the first click, is not yet there.
You load it via $_GET, but it has not yet been loaded the first click. That click, however, renders the page and now loads the value.

To be sure, you might wish to check the URL, which, as $_GET type, will show you the current value for 'waybillno'. Your function, which is called on button click, has the most recent value from .php, but that hasn't been set until after your first click.

(pass the value to your function with the button click, via javaScript, from your page body, instead of using .php at that point).

 
Share this answer
 
v2
Correct, but I am looking for a way for the value to be set in the script after the first click. Is this possible at all?
I have added the $Get as part of my Javascript function, but it still only works after the 2nd click.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900