Login | Register | FAQ
Anonymous

Changing image src according to drop down menu

+ Post a reply

2 posts Page 1 of 1


Changing image src according to drop down menu

by blacblu » Mon Jul 02, 2012 1:14 am

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=true

It'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
User avatar

blacblu

  • Posts: 5
  • Joined: Fri Jun 29, 2012 12:26 am

Re: Changing image src according to drop down menu

by XainPro » Mon Jul 02, 2012 7:22 am

i think you need jquery
you 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>
User avatar

XainPro

  • Posts: 3669
  • Joined: Fri Feb 17, 2012 8:10 pm


+ Post a reply

Page 1 of 1