Bill
Bill

Reputation: 79

Pass value from parent to iframe dropdown box

I need to pass a value from a parent to an iframe (on a different server, not in my control) and have the value make a selection in a dropdown in the iframe.

Example: mydomain.com/?agent=12345 (target will be the iframe)

In the iframed page, the dropdown has several choices, I need to have the value in the url be the selected the choice corresponding to the selection when the link is clicked and the page is loaded in the iframe.

Is passing in the URL possible or do I use JS, PHP? If JS or PHP, how?

Thanks.

Upvotes: 0

Views: 656

Answers (1)

Robbie
Robbie

Reputation: 17710

You can use either.

If PHP then use $_GET to read the parameter, and when building the page set selected="selected" in the option that meets the requirements.

If javascript then load the page as normal and then, onload, read the parameters and find the select box and set the select box appropriately.

You'll find PHP easier as this has the parameter in $_GET, whereas in Javascript you need to get the URL from the string (although there are functiosn on the web you can use). If you do use Javascript and haven't done it before, use jQuery to set the select box as there are also plenty of examples available online.


Editing answer (for archiving, based on clarifying comments below).

Clarification was the iFrame can't be edited as it belongs to another domain - so the manupulation has to come from the parent domain.

Based on this - it's not possible. Browser security prevents sites manipulating content in frames across domains. Otherwise you would be able to create a frame that completed the entire form for the user and submits it in their name. The only solution is to edit the child frame.

Upvotes: 1

Related Questions