Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
explode an array to get the value for cngColor(img)

 
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help
View previous topic :: View next topic  
Author Message
elwood773
New one
New one


Joined: 14 May 2008
Posts: 1
Location: Montreal

PostPosted: Wed May 14, 2008 5:30 pm    Post subject: explode an array to get the value for cngColor(img) Reply with quote

Hi guys,
I am quite new to ajax / javascript and I admit that I feel more confortable with regular php and c++ rather than JS. So, I am stuck in front of this bug since a little while and I would like to have your help, please.

Here's my problem: I work to fix up many things on an existing shopping cart website and I need to change the top image according to the selected color in a dropdown list. The issue is that list is generated in php by the reply from the sql database, not a simple index number from the dropdown list. So, I need to work with an array and explode it in several parts and here's where I lost my way. The color is the second item in the array. Could you have a look to the code I included, please. Thanks in advance for your help.

Code:
<script language="JavaScript" type="text/javascript">
function CngColor(obj){

var Path='http://www.xyz.com/images_products/xyz_colors/';
var str=obj.options[index].value;
var wantedColor=(str.split("||"));

index=obj.selectedIndex;
var wantedColor = obj.options[1].value
if (index<1){ return; }
document.getElementById('largeimage').src=Path+wantedColor;
}
</script>
<?
  $id = $_GET['id'];
  if(!preg_match('/^[a-zA-Z0-9]+$/', $id))
  {
    header('Location: ?page=message&id=2');
  }
  $sql = "SELECT DISTINCT products.num,name,color " . 
       "FROM products,product_detail " .
       "WHERE products.num = product_detail.num AND product_detail.num ='". $id . "'";
 
       
  $result = mysql_query($sql, $link);
  $contents = mysql_fetch_assoc($result);
  $numRows = mysql_num_rows($result);

  if($numRows < 1)
  {
    header('Location: ?page=message&id=5');
  }
    $id = $contents['num']
?>
<h3><?= $contents['name'] ?></h3>
<table>
<tr><td><? print"<img id=\"largeimage\"  src=\"images_products/large/" . $id . "_" .$contents['color'].".jpg\" onError=this.src='images/default_large.jpg' /></td><td><p>". $contents['desc']."</p></td>";?>
<td><table>
  <?
     $sql = "SELECT DISTINCT color " . 
            "FROM product_detail " .
           "WHERE num ='". $id . "'";
      $result = mysql_query($sql, $link);
        while($colors = mysql_fetch_assoc($result))
        {
         if($id != 'r001')
          {
             print "<tr><td><img src=\"images_products/xyz_colors/" .$colors['color'].".jpg\" id=\"xyzcolor\"                onClick=\"changeImage('".$id."','".$colors['color']."')\"/></td><td>".$colors['color']."</td></tr>" ;
        }
         
        }
 
  ?>
  </table></td>
</tr>
</table>

  <select name="dropdownlist" onchange="CngColor(this);">
   <?   
     $sql = "SELECT * FROM product_detail " .
         "WHERE num = '" . $id . "' ORDER BY size";
       $result = mysql_query($sql, $link);
   ?>
   
   <?
        while($contents = mysql_fetch_assoc($result))
      {?>
            
           <option name="<?= $id ?>_details" type="radio" value="<?= $contents['size'] . "||" . $contents['color'] . "||" . $contents['price']?>" id="<?= $id ?>_details" >

   

      
      <?=$contents['size'] . " - " . $contents['color'] . " - $" . number_format($contents['price'], 2, '.', ',')?></option><br />
    <? }?></select><br/>
    Please enter the amount you wish to purchase: <input type="text" id="<?= $id ?>_quantity" size="1" maxlength="3" value="1"/>
    <input type="button" onClick="sendInfo('<?= $id ?>');" value="Add to cart"/>
<img src="images/wait_spacer.gif" alt="wait_spacer.gif" id="<?= $id ?>_img"/>
<div id="<?= $id ?>"></div>
<a href="?page=viewCart&id=">View Cart</a>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 Advertisements
 XML & Copyright Notice 
    


Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X


Link to our site:

  


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos


Normal Bookmark


Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax


Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?


Credits:
it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert