| | #1 |
| 100% Warrior War Room Member Join Date: 2012 Location: New Zealand
Posts: 588
Thanks: 90
Thanked 76 Times in 71 Posts
|
I have a page/form which I need to iframe into my website for branding purposes. The page/form I want inside the iframe has a dropdown menu which I have no control over.. but need to have that dropdown pre-select a particular menu item when it loads inside my iframe.. How do I do this? |
| | |
| |
| | #2 |
| Active Warrior Join Date: 2012
Posts: 97
Thanks: 12
Thanked 12 Times in 11 Posts
|
here what you do: Warning: this works only on server side, otherwise you will see security errors and warnings. file1 <html> <body> <!-- your iframe, see file2 below --> <iframe src="frame.html" frameborder="0" width="500" height="300" id="iiframe"></iframe> <!-- get latest jquery library from google apis --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> <!-- jquery code below find in iframe with ID:iiframe, the element with ID:selcolor and option attribute value="green" and marks it as selected --> <script type="text/javascript"> (function(){ $('#iiframe').contents().find('#selcolor option[value="green"]').attr('selected', 'selected'); })(); </script> </body> </html> file2 <html> <body> <select name="selcolor" id="selcolor"> <option value="red">Red</option> <option value="green">Green</option> <option value="blue">Blue</option> </select> </body> </html> |
| |
| The Following User Says Thank You to viescripts For This Useful Post: |
| | #3 |
| 100% Warrior War Room Member Join Date: 2012 Location: New Zealand
Posts: 588
Thanks: 90
Thanked 76 Times in 71 Posts
|
Thanks vie.. i'll have a play with it tomorrow.
|
| | |
| |
| | #4 |
| Active Warrior Join Date: 2012
Posts: 97
Thanks: 12
Thanked 12 Times in 11 Posts
| |
| |
| | #5 | |
| Web Developers Join Date: 2012
Posts: 22
Thanks: 1
Thanked 5 Times in 5 Posts
|
Code: <select id="dropdown_options">
<option id="one">Option one</option>
<option id="two" selected>Option two</option>
<option id="three"> Option three</option>
</select> Code: <select id="dropdown_options">
<option id="one">Option one</option>
<option id="two">Option two</option>
<option id="three"> Option three</option>
</select>
<script type="text/javascript">
(function()
{
document.getElementById("dropdown_options").options["two"].selected = true;
})();
</script> Note: just to be clear, you can access the iframe source in JavaScript like so: Code: <iframe name="test" id="test"></iframe>
<script type="text/javascript">
console.log(test.document);
</script> | |
| | ||
| |
| | #6 |
| Active Warrior Join Date: 2012 Location: Edmonton AB, Canada
Posts: 52
Thanks: 0
Thanked 3 Times in 3 Posts
|
This is great, thanks!
|
|
Discover How To Quit Your Job And Work Online In My Free Video Course! http://mikestankowski.com/quityourjob | |
| |
|
| Bookmarks |
| Tags |
| dropdown, iframe, select |
| |