Ritzy Ritzy - 5 months ago 9
Javascript Question

Opening a form in an iFrame instead of new window

Currently I have the following code.

<form method="get" id="searchform" action="/scraper/l.php?">
<div>
<input type="text" placeholder="Some Name Here" value="" name="n" id="n" style="padding: 7px; border: 1px solid #ddd;width: 75%;">
<input type="submit" id="searchsubmit" value="Index" class="btn" style="padding: 6px; color: #fff; background-color: #ed207b; border: 2px solid #ed207b;">
</div>
</form>


I am trying to make it so that it opens the path
example.com/scraper/l.php?n=(Our ID)
in an iFrame window on the same page appose to creating a new window.

Answer

based on your requirement, you can check whether the $_GET['n'] param is set when the page is loaded.(because you are submitting to the same page itself) if it is loaded, you can display the iframe. since you are using php, i will give you the exact code as follows.

<html>
<head>
</head>
<body>
<form method="get" id="searchform" action="/scraper/l.php?">
<div>
    <input type="text" placeholder="Some Name Here" value="" name="n" id="n" style="padding: 7px; border: 1px solid #ddd;width: 75%;">
    <input type="submit" id="searchsubmit" value="Index" class="btn" style="padding: 6px; color: #fff; background-color: #ed207b; border: 2px solid #ed207b;">
</div>
</form>

<?php
if(isset($_GET['n']) && !empty($_GET['n'])){
?>

 <iframe src="http://www.google.com"></iframe> 

<?php
}
?>
</body>

</html>