/    Sign up×
Community /Pin to ProfileBookmark

Images change by selection box, can’t find my error !!!

Good day to you all,
In the following code it’s a form and within this form user can choose an image from a selection box. Beside the selection box there is an images that is “supposed” to change by the choice they make in the selection box.

When you change the selection in the selection box, the image goes blanck, it can find it, I’m sure I have done an erore somewhere can somebody help me with this please ?

I’m with php4 and windows 2003.

here is the code :

[code=php]
<?PHP
function PGL_ConfigList($dir)
{
$pattern=”.(jpg|jpeg|png|gif|bmp)$”;
$files = array();
if($open = opendir($dir))
{
while(false !== ($file = readdir($open)))
{
if(eregi($pattern, $file) && !is_dir($file))
{
$files[] = $file;
}
}
}
closedir($open);

return($files);
}
$dir = “./upload/”;
$list = PGL_ConfigList($dir);
echo “<select name=”image” onchange=”noimage.src=’$file'”>”;
foreach($list AS $file)
{
echo “<option value=”$file”>$file</option>”;
}
echo “</select>”;
?>
<br>
<img src=”upload/peuplies-1-man-small.bmp” width=”200″ name=”noimage”>

<br>
<input type=”submit” name=”submit” value=”Submit”>
</form>
</fieldset>
</td>
</tr>
</table>
</body>
</html>

[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@JayMMay 21.2007 — The reason it doesn't work is because it has no idea what the value of the variable $file is.

Here you go:
[code=php]
echo "<select name="image" onchange="noimage.src=this.value">";
[/code]
×

Success!

Help @Peuplarchie 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.29,
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,
)...