Hello I was wondering who can help me with this…. I am trying to make to make the correct code in php…. Is a simple Form you will type a number from 1 to 10 and I want as a result to open a popup window with googles site for example, type a number from 11 to 20 and open a popup window with yahoos site, and so on….

I was able to make the form with $quantity in simple form html:

<form action="result.php" method="post">
Number: <input name="quantity" type="text" />
<input type="submit" />
</form>

Result PHP page:

<?php
$quantity = $_REQUEST["quantity"];
if ($quantity >= 1 && $quantity <= 10) {
echo "Write example 1";
} else if ($quantity >= 11 && $quantity <= 20) {
echo " Write example ";
} else if ($quantity >= 21 && $quantity <= 30) {
echo " Write example ";
} else {
echo "Does not exist";
}

Well my question I guess is how can I make echo open a href in a new window depending on the imput? Seen Javascript used however I can´t seem to make it work where and how could I do this…

Any help will greatly appreciate it…

Total noob ;o)

    <?php
    echo "<a href=\"index.php\" target=\"_blank\">title</a>";
    ?>
    

    You should know what to change.

      Moved to ClientSide Technologies forum, since the request has nothing to do with PHP.

        You could try

        <?php
        echo '<script type="text/javascript" language="javascript">
        window.open("http://www.something.com");
        </script>';
        ?>
        

        Or instead of having php do the work, have javascript do it all.

        <script type="text/javascript" language="javascript">
        function OpenWindow() {
        	var quantity = document.getElementById('quantity').value
        
        if ((quantity >= 1) && (quantity <= 10)) {
        	window.open('http://www.something.com');
        } 
        else if ((quantity >= 11) && (quantity <= 20)) {
        	window.open('http://www.somethingelse.com');
        } 
        else if ((quantity >= 21) && (quantity <= 30)) {
        	window.open('http://www.anothersomething.com');
        } 
        else {
        	window.open('http://www.gonowhere.com');
        }
        }
        </script>
        
        <form action="result.php" method="post">
        	Number: <input id="quantity" type="text" />
        	<button type="button" onclick="OpenWindow()">Submit</button>
        </form>
        

        For more information on the window.open check out w3school.com

          Write a Reply...