Changing image src according to drop down menu
Page 1 of 1
Changing image src according to drop down menu
I have a image like with the url like this: api.cosm.com/v2/feeds/52753/datastreams/Hidro3.png?width=1000&height=300&colour=%23f15a24&duration=1day&legend=Litros&title=Hidr%C3%B4metro&show_axis_labels=true&detailed_grid=trueIt's a graphic and I'm trying to do a scale selector, changing that part of the url, but when I change something on the dropdownmenu nothing happens.
What am I doing wrong?
Thank you.
- Code: Select all
<html>
<head>
<title>Home2</title>
</head>
<script language = "Javascript">
function jsDropDown(imgid,buiildingnumber,apartmentnumber,newimg){
document.getElementById(imgid).src = "https://api.cosm.com/v2/feeds/"+ buildingnumber +"/datastreams/Hidro" +apartmentnumber+ ".png?width=1000&height=300&colour=%23f15a24&duration="+newimg+"&legend=Litros&title=Hidr%C3%B4metro&show_axis_labels=true&detailed_grid=true "
}
</script>
<style type="text/css">
div.transbox
{
opacity:0.93;
filter:alpha(opacity=96);
border:1px solid black;
width: 1002px;
height: 350px;
}
</style>
<body style="background-image:url(novofundo.jpg)">
<?php
mysql_connect("", "", "");
mysql_select_db("") or die(mysql_error());
/////////////////////////////////////////////////////////////////////////////////////////
$query = sprintf ("SELECT Password FROM Users WHERE Username = '$_POST[username]'",
mysql_real_escape_string($Password));
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
$strpassword = $row['Password'];
}
$query = sprintf ("SELECT Buildingnumber FROM Users WHERE Username = '$_POST[username]'",
mysql_real_escape_string($Buildingnumber));
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
$strbuildingnumber = $row['Buildingnumber'];
}
$query = sprintf ("SELECT Apartmentnumber FROM Users WHERE Username = '$_POST[username]'",
mysql_real_escape_string($Apartmentnumber));
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
$strapartmentnumber = $row['Apartmentnumber'];
}
if(strlen($_POST[password]) > 0 && strlen($_POST[username]) > 0){
if($strpassword == $_POST[password]){
session_start();
$_SESSION["Login"] = "YES";
$selected = $_GET["selected"];
if($selected == ''){
$selected = "1month";
}
echo "<h1>Olá " .$_POST["username"]. ". Seja bem vindo.</h1>";
echo "<center><div class='transbox';>";
echo "<img src='
https://api.cosm.com/v2/feeds/".$strbuildingnumber."/datastreams/Hidro".$strapartmentnumber.".png?width=1000&height=300&colour=%23f15a24&duration=1day&legend=Litros&title=Hidr%C3%B4metro&show_axis_labels=true&detailed_grid=true'
id ='cful' alt='imagem'/>
<p><select name='food' align='left'; id='myList' onChange='JsDropDown('cful','".$strbuildingnumber."','".$strapartmentnumber."',this.value)'>
<option>Select</option>
<option value='1hour'>1 hour</option>
<option value='12hours'>12 hours</option>
<option value='1month'>1 month</option>
<option value='3months'>3 months</option>
<option value='1year'>1 year</option>
</select></p>
</div>
</center>";
}
else{
session_start();
$_SESSION["Login"] = "NO";
echo "<h1>Seus dados estao incorretos.</h1>";
}
}else{
session_start();
$_SESSION["Login"] = "NO";
echo "<h1>Você deixou um ou mais campos em branco.</h1>";
}
mysql_free_result($result);
?>
</body>
</html>
echo
Re: Changing image src according to drop down menu
i think you need jqueryyou can change src attribute of an img element through jquery like this
- Code: Select all
<!DOCTYPE html>
<html>
<head>
<style>
img { padding:10px; }
div { color:red; font-size:24px; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<img />
<img />
<img />
<div><B>Attribute of Ajax</B></div>
<script>
$("img").attr({
src: "/images/hat.gif",
title: "jQuery",
alt: "jQuery Logo"
});
$("div").text($("img").attr("alt"));
</script>
</body>
</html>
Page 1 of 1