endriu
endriu

Reputation: 15

Pass a variable to iframe src

I need your super help to end a project. I've a homepage.html that contains a drop down menu generated by different < option >. at the end of the form I have submit button that leads to booking.html page that contains an iframe.

I would need to take the value (number) generated by previous form and put it at the end of the url of the src iframe, so that the iframe changes depending on the previous choice.

and..the src is on a different domain. So the final result would be something like: < iframe src="domain2.com/?=dynamic_number" >

I have no idea how to do that.

Thanks in advance and sorry for my bad English..

Upvotes: 0

Views: 3051

Answers (1)

JuanBonnett
JuanBonnett

Reputation: 786

In case you can use a Server Side script like PHP:

Form:

<form method="post" action="booking.php">
    <select name="myUurlParameter">
    <option value="1"></option>
    <option value="2"></option>
    <option value="3"></option>
    </select>
</form>

Booking.php

<?php
$urlParam = $_POST["myUrlParameter"];
?>
<html>.... ....

<iframe src="http://thewebsite.com/?param=<?php echo $urlParam ?>" ...></iframe>

You can also use Javascript (it's complicated tho) ...

Change the above form method to GET, change the action to your .HTML file (Booking.html)

Inside booking, generate the iframe dinamically using javascript. Read this answer to know how to do it (again, it's complicated... )

How to get the value from the GET parameters?

Upvotes: 1

Related Questions