Narzard
Narzard

Reputation: 213

Change src of iframe with an input box on another page

Here is what I am trying to accomplish:

Homepage: have a search bar/input field that inputs into an string (src of iframe) on another page. The site is PHP. I do not know what all files I will need.

On homepage:

searchbox

Other page with iframe I need the input from search to

<iframe src="https://www.tradingview.com/e/?symbol= 'SEARCHBOX CONTENTS' >

The people using the site will know to enter a ticker symbol (stock symbol).

Thanks for any help!

Upvotes: 0

Views: 417

Answers (2)

Oki Erie Rinaldi
Oki Erie Rinaldi

Reputation: 1863

You may POST your searchbox input into a php or a php page that contains the iframe that you mean. for example :
i consider you have a form :

<form action='frame.php' method='POST'>
<input type='text' name='keyword'><input type='submit' value='search'>
</form>

Your frame.php:

<?php 
$keyword = $_POST['keyword'];
echo "<iframe src='$keyword'></iframe>";
?>

That's all if you just want to fill src attribute of an iframe.
But, I think it would not working properly, because src of an iframe must be a link to a file (included it's filename and extension). so if it's just a keyword, you have to process the keyword before you attach it into src atrribute.
I suggest you to use jquery, ajax, and json if you want your web page looks more dynamic

Upvotes: 0

xlordt
xlordt

Reputation: 521

Is this what you mean? If so, please note you will need to handle some security checks. on the input string.

<?php  //create a php page and name it what ever

  $iframe = null;

  if (isSet ($_POST ['submit']))
  {
      if (!empty ($_POST ['search']))
          $iframe = "<iframe src='https://www.tradingview.com/e/?symbol={$_POST ['search']}'' width='800' height='600'>";
  }

?>

<form method="post" action="">
 <input type="text" name="search"><input type="submit" name="submit" value="searc">
</form>

<?php echo $iframe; ?>

Upvotes: 1

Related Questions