PDA

View Full Version : iframe src as variable


stickers
08-16-2010, 03:33 PM
Hi,


How do I set the src of the iframe to equal the variable, in the html body?

I am working with 2 files and I am trying the following - no success!

The first file redirects the user from one page to another.

file.html
______

<div align=center>
<form id=url type=get action=file.asp>
<input type=text name=URL size=30>
<input type=submit name="url2" value="Enter Url">
</form>
</div>

file.asp
______


<html>
<head>

<script type="text/javascript">
document.write('<iframe src="' + url2 + '"></iframe>');
</script>

</head>

<body>

<iframe id="iframe1" width="800" height="600" src="url2" APPLICATION="yes"></iframe></div>


</body>
</html>


Thanks!

Stickers :D

Old Pedant
08-16-2010, 06:57 PM
Do you need/want to do it in JavaScript, as you are showing? (If so you are in the wrong forum, but the answer is easy.)

Or do you really want to do it in ASP code?

The real question is this: *WHERE* is the value of the variable url2 defined? In ASP code or in JavaScript code?????

Oh, w.t.h. Both answers:

If url2 is defined in ASP code:

<iframe id="iframe1" width="800" height="600" src="<%=url2%>" APPLICATION="yes">
</iframe>

If it is defined in JavaScript code:

Two possible ways:

[code]
<body onload="document.getElementById('iframe1').src=url2;">
...
<!-- notice there is NO src= here: -->
<iframe id="iframe1" width="800" height="600" APPLICATION="yes">
</iframe>

or (not as elegant but works):

<script type="text/javascript">
document.write(
'<iframe id="iframe1" width="800" height="600" src="' + url2 + '" APPLICATION="yes">'
+ '</iframe>' );
</script>