Forum Moderators: coopster

Message Too Old, No Replies

Change iframe src

With some php

         

Sub_Seven

7:46 pm on Dec 21, 2010 (gmt 0)

10+ Year Member



Hey guys,

I have another question, I might be a little lost here

Say these are different images stored in a MySQL db:

[url...]
[url...]
[url...]

I have a page with 6 iframes and I want to give people the option to choose which image to display in each iframe.

I created the following variable to only change the last digit:

$pic_url = "http://url/show.php?id=";

and this is the iframe
<iframe class="ifimage" src="<?php echo $pic_url; echo ('1') ?>" frameborder="0">
<p>Your browser does not support iframes.</p>
</iframe>


As you can see that second echo is adding the number 1 and it works fine but I would like to be able to put an input field or something that the user can update and change that number to whatever they want and get a different picture displayed, can this be done?

I hope this is clear enough, thanks in advance for all the help.

elf_red

10:35 pm on Dec 21, 2010 (gmt 0)

10+ Year Member



<input type=text onKeyUp="document.getElementById('IframeId').src='<?php echo $pic_url;?>'+this.value;">

rocknbil

6:28 pm on Dec 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Validator doesn't like target in some doctypes (which I will never, ever understand), but it still works, and it's valid for 4+ and 5. Change "https" to "http" - did that so the links render properly on this board.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Untitled</title>
<style type="text/css">
ul,iframe { width: 500px; text-align: center; }
ul li { display: inline; }
</style>
</head>
<body>
<iframe src="https://www.webmasterworld.com" id="my-iframe" name="my-iframe"></iframe>
<ul>
<li><a href="https://www.google.com" target="my-iframe">Google</a> | </li>
<li><a href="https://www.amazon.com" target="my-iframe">Amazon</a> | </li>
<li><a href="https://www.webpagesthatsuck.com" target="my-iframe">Web Pages That Suck</a></li>
</ul>
</body>
</html>

So all you'd do is . . .

<ul>
<?php
for ($i=1;$i<7;$i+) {
echo "<li><a href=\"https://url/show.php?id=$i\">$i</a></li>\n";
}
?>
<ul>

The advantages of this approach:

- Your links will still index.
- accessibility for all, no Javascript required
- Simplicity in coding and maintenance.

Readie

10:34 pm on Dec 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Validator doesn't like target in some doctypes (which I will never, ever understand)


Just XHTML I believe. Happily, the next XHTML standard will (apparently) validate with target again! :)

Matthew1980

11:34 pm on Dec 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi all,

Yes I recall a thread on this very subject a while back, (x)html 5 has 'given back' this directive, though it still works, people & clients who want complete validation passes (with the exception of adsense & some google things in their own frames) can once again have their sites pass in all sects of validation, so I for one, haven't tried to find another way, I just stuck with the target directive where they were before.

I haven't been able to find a complete list of 'allowed' tags for 5 yet though. I am sure that if I looked hard enough I would find something :)

Cheers,
MRb

rocknbil

5:55 pm on Dec 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think 4.01 strict kicks it too. 'Tis stooopid, target is a valuable asset. :-)

Matthew1980

3:48 pm on Dec 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>>I think 4.01 strict kicks it too. 'Tis stooopid, target is a valuable asset. :-)

2nd'ed!

Cheers,
MRb

Sub_Seven

8:42 pm on Dec 24, 2010 (gmt 0)

10+ Year Member



Thanks elf_red, that's what I needed, worked great.

@rocknbil, I'm not sure I understand how your example can be applied to what I needed or maybe I just don't understand it, if it isn't too much to ask please explain.

Merry christmas to everybody :)