iframe src variables

M

mkhines

I'm having trouble figuring out the proper way to pass this variable
in with javascript alone. I'm not used to not being able to use jsp
and all the love that is in that.

Obviously I know little about javascript!

So you get the whole story, the user will begin on a page which has an
iframe in it that picks up a parameter
http://wildlifedisease.nbii.gov/ecoregions/theirpage.html

which contains an iframe that passes a parameter when the form is
submitted to ANOTHER page with an iframe which needs to pick up that
parameter.

So, for example, if you put in 11211 in the text box on the first
page, and submit it, it opens a new window and pushes over the zipcode
parameter value to that next page
http://wildlifedisease.nbii.gov/ecoregions/bigpage.html?zipcode=11211

what i need to do now, is get the iframe in bigpage.html to pick up
that zipcode parameter.

i'm using a substring function (here's the code for bigpage.html) to
get the zipcode value

<html>
<body>
<script type="text/javascript">
var zipcode2=window.location.search.substring(9);
alert(zipcode2);
</script>
<iframe frameborder="0" height="100%" width="100%"
src="http://wildlifedisease.nbii.gov/ecoregions/index.jsp?zipcode=
+zipcode2.value+"></iframe>
</body>
</html>

which works fine, but I can't figure out how to properly write the
src="" part.. i've tried every combination of apostrophes and plus
signs, argh!

help?

Thanks!!!!
 
Á

Álvaro G. Vicario

mkhines escribió:
<html>
<body>
<script type="text/javascript">
var zipcode2=window.location.search.substring(9);
alert(zipcode2);
</script>
<iframe frameborder="0" height="100%" width="100%"
src="http://wildlifedisease.nbii.gov/ecoregions/index.jsp?zipcode=
+zipcode2.value+"></iframe>
</body>
</html>

You can't just insert JavaScript code anywhere in your HTML. If you
write "zipcode2.value", how can the browser know it's not HTML?

You probably want something like this, but please make sure you
understand why your code did not work and you'll prevent lots of headaches.

<script type="text/javascript"><!--
var zipcode2=window.location.search.substring(9);
// This is only one line, it was wrapped by my newsreader:
document.write('<iframe frameborder="0" height="100%" width="100%"
src="http://wildlifedisease.nbii.gov/ecoregions/index.jsp?zipcode=' +
escape(zipcode2.value) + '"><\/iframe>');
//--></script>

Code is not tested.

Be aware that your iframe won't event exist for non JS aware user agents.
 
M

mkhines

mkhines escribió:


You can't just insert JavaScript code anywhere in your HTML. If you
write "zipcode2.value", how can the browser know it's not HTML?

You probably want something like this, but please make sure you
understand why your code did not work and you'll prevent lots of headaches..

<script type="text/javascript"><!--
var zipcode2=window.location.search.substring(9);
// This is only one line, it was wrapped by my newsreader:
document.write('<iframe frameborder="0" height="100%" width="100%"
src="http://wildlifedisease.nbii.gov/ecoregions/index.jsp?zipcode='+
escape(zipcode2.value) + '"><\/iframe>');
//--></script>

Code is not tested.

Be aware that your iframe won't event exist for non JS aware user agents.

--
--http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--

Thanks, I eventually did this based on another recommendation. I do
see that as a problem, but if I need to pass variables to an iframe on
a different group's server, i'm not sure there is any other way for me
to do what i'm trying to do.. we need to host the application on a
server that can run tomcat/database etc. and they don't have that
ability.

(here is the code i went with in the end)
<html>
<script type="text/javascript">
function init() {
var zipcode2 = window.location.search.substring(9);
var url = "http://wildlifedisease.nbii.gov/ecoregions/
index.jsp?zipcode=" + zipcode2;
document.getElementById("myframe").src = url;
}
</script>
<body onLoad="init()">
<iframe id="myframe" frameborder="0" height="100%" width="100%"
src=""></iframe>
</body>
</html>

is there some other way to pass those variables to the iframe without
javascript?

thanks!

megan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top