/    Sign up×
Community /Pin to ProfileBookmark

Changing src of Iframe from a dropdown

Hi,

I’m trying to change the src of an Iframe from the values passed from a select box, but even though its not coming up with any errors it still isn’t working. I was wondering if someonecould have a quick look at the code to see if I’ve made an obvious mistake.

[code=php]
<!– DROP DOWN–>
<SELECT name=”VERSION” style=”border: 1 solid #C0C0C0; padding: 0; background-color: #ffffff; font-family: arial; font-size=8pt; color: #959494;” onChange=”document.iView.src=this.options[this.selectedIndex].value;”>
<OPTION SELECTED value=”page2.asp”>– Select a version to work on –</OPTION>
<OPTION value=’page.asp?ID=1′>05/05/05</OPTION>
<OPTION value=’page.asp?ID=2′>Blank</OPTION>
<OPTION value=’page.asp?ID=3′>Blank</OPTION>
</SELECT>

<!– AND FUTHER DOWN THE CODE THERE IS THE IFRAME CODE–>

<iframe id=”iView” name=’iView’ style=”width: 524px; height:100%” src=”></iframe>
[/code]

Cheers in advance

Phil

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@ggriffitMay 06.2005 — try something like :

document.iView.src=document.<form name>.VERSION.options[document.<form name>.VERSION.selectedIndex].value;
Copy linkTweet thisAlerts:
@NileshXYZMay 06.2005 — here you go...

[CODE]<SELECT name="VERSION" style="border: 1 solid #C0C0C0; padding: 0; background-color: #ffffff; font-family: arial; font-size=8pt; color: #959494;" onChange="iView.location=this.value;">
<OPTION SELECTED value="page2.asp">-- Select a version to work on --</OPTION>
<OPTION value='http://www.google.com'>05/05/05</OPTION>
<OPTION value='page.asp?ID=2'>Blank</OPTION>
<OPTION value='page.asp?ID=3'>Blank</OPTION>
</SELECT>
[/CODE]



www.define-web.com

Nilesh
Copy linkTweet thisAlerts:
@scouseauthorMay 06.2005 — Thanks guys for your help.

ggriffit, I tried your way, but I still couldn't get it to work, I think I was doing something wrong... just not quite sure what! Thanks anyway, I really appreciate it.

NileshXYZ, it worked a treat. Thanks very much!

I've just got another question:

As well as changing the iframe contents to the relevent page I'd like to pass a unique ID variable for each selection to a hidden field on my main page. Is this possible by using the onchange event?

Thanks
Copy linkTweet thisAlerts:
@scouseauthorMay 06.2005 — Right, I've changed the original thing a little bit as I needed to somehow try and solve the other problem I had and I managed to create this function:


[code=php]

function captureChange()
{
varName=document.form1.VERSION.options[document.form1.VERSION.selectedIndex].value
document.form1.ID.value=varName;
alert (varName)
iView.location="page1.asp?ID=" + varName
}

<!-- IFRAME -->

<iframe id="iView" name='iView' style="width: 524px; height:100%" src='page2.asp'></iframe>


<!-- FORM-->

<form name="form1" method="post" >

<SELECT name="VERSION" style="border: 1 solid #C0C0C0; padding: 0; background-color: #ffffff; font-family: arial; font-size=8pt; color: #959494;" onchange="captureChange()">

<OPTION value='1'>05/05/05</OPTION>
<OPTION value='2'>Blank</OPTION>
<OPTION value='3'>Blank</OPTION>
</SELECT>

<input type='HIDDEN' name='ID' value=''>

[/code]


Now every time I try to select an option it displays the alert and shows the correct ID and places it in the hidden field, but it won't change the src of the Iframe. Instead one of Microsofts stupid "an error has occured, the window must close... but you can send an error report if you want" things keeps coming up.

Any ideas?
×

Success!

Help @scouse spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...