Why function f() is not working on click on images.

Kindly have a look on code, why function f() is not working.
Secondly, what ever product image in click it should get assigned to cp id of img tag.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testp.aspx.cs" Inherits="testp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Iconic Fabrics</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/skin.css" />
<script src="js/jquery.min.js"></script>
<script src="js/script.js"></script>
<script src="js/autoadvance.js"></script>
<script type="text/javascript" src="js/jquery.jcarousel.min.js"></script>
<script type="text/javascript">
function f()
{
if(document.getElementById('i1').src=="testiconic/images/product1.jpg")
{
    alert('Product1 selected');
    cp.src="images/product1.jpg";
}
else if(document.getElementById('i2').src=="testiconic/images/product2.jpg")
{
    alert('Product2 selected');
    cp.src="images/product2.jpg";
}
else if(document.getElementById('i3').src=="testiconic/images/product3.jpg")
{
    alert('Product1 selected');
    cp.src="images/product3.jpg";
}
else if(document.getElementById('i4').src=="testiconic/images/product4.jpg")
{
    alert('Product1 selected');
    cp.src="images/product4.jpg";
}

   
}

</script>
<style>

h3{
      font-size:35px;
      float:left;
      color:#02a3fb;
      padding:0 0 0 15px;
      font-weight:normal;
}

</style>
<script type="text/javascript">

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
          wrap: 'circular'
    });
});

</script>
</head>

<body>
<div class="container">
      <div class="header">
          <a href="javascript:;" class="logo"></a>
        <div class="blank_area">
               <div class="toplinks">
                  <a href="javascript:;" title="Login"   onClick="ShowHideSignInDiv()">Login</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="javascript:;" class="">Signup</a>
               
                <span>
                                   <div id="divSignIn" class="signInBg" >
                                <table width="100%" border="0" align="center" cellspacing="0" cellpadding="0" class="signIn_mid-bg" style="padding: 0 0 10px 20px;;">
                                <tr>
                                  <td height="20"class="font_style">Username</td>
                                </tr>
                                <tr>
                                  <td height="30"><input name="input" type="text"   class="login_input-bg" /></td>
                                </tr>
                                <tr>
                                  <td height="20" class="font_style">Password</td>
                                </tr>
                                <tr>
                                  <td height="30"><input name="input" type="password"  class="login_input-bg" /></td>
                                </tr>
                                <tr>
                                  <td  valign="top">
                                  <table cellpadding="0" border="0"  width="100%" cellspacing="0">
                                      <tr>
                                        <td>
                                            <input name="input" type="checkbox" value=""/></td>
                                        <td ><a href="#javaScript" class="forgot">Remember me</a></td>
                                       
                                        <td align="right">
                                              <a href="#javaScript:;" title="Login">
                                            <img src="images/login_btn.gif" alt="" style="margin:10px 11px 0 0px;" />
                                            </a>
                                        </td>
                                      </tr>
                                  </table></td>
                                </tr>
                                <tr>
                                  <td align="left">
                                      <h5><a href="#javaScript" class="forgot">Forgot password?</a></h5></td>
                                </tr>
                                <tr>
                                  <td align="left">
                                      <h5><a href="#javaScript" class="facebook-login"><img src="images/facebook-login-button.png" /></a></h5>
                                  </td>
                                </tr>
                            </table>        
                        </div>
                             
                              </span>
              </div>
            <div class="cart_outer">
                  <span>cart(0)</span>
            </div>
        </div>    
       
    </div>
    <div class="navigation">
          <ul>
              <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Gallery</a></li>
            <li><a href="#" class="selected">Product</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </div>
   
    <div class="page">
          <div class="page-other-top"></div>
        <div class="page-other-cen">
              <div class="content-container"><h3>Product Gallery</h3></div>
            <h2>Choose Your Product Here</h2>
            <div class="products-outer">
                   <ul id="mycarousel" class="jcarousel-skin-tango">
                    <li><a href="javascript:;"><img id="i1" src="images/product1.jpg" width="178" height="160" alt="" onclick="f()"/></a><h5>Cup</h5></li>
                    <li><a href="javascript:;"><img id="i2" src="images/product2.jpg" width="178" height="160" alt="" onclick="f()"/></a><h5>French Chair</h5></li>
                    <li><a href="javascript:;"><img id="i3" src="images/product3.jpg" width="178" height="160" alt="" onclick="f()"/></a><h5>Cushion</h5></li>
                    <li><a href="javascript:;"><img id="i4" src="images/product4.jpg" width="178" height="160" alt="" onclick="f()"/></a><h5>Pouffe</h5></li>
                   </ul>
            </div>
           
             <h2 class="mt20">Choose product fabric here</h2>
             <div class="line"></div>
             <div class="fabrics">
                   <div class="fabric-box">
                      <img id="f1" src="images/fab1.jpg" border="0"  onclick="this.value/>
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab2.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab3.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab4.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab5.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab6.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab7.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab8.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab9.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab10.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab1.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab2.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab3.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab4.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab5.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab6.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab7.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab8.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab9.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
                <div class="fabric-box">
                      <img src="images/fab10.jpg" border="0"  />
                    <h5>Fabric Name</h5>
                </div>
             </div>
        </div>
       
        <div class="page-other-bot"></div>
    </div>
    <div class="footer">
          <div class="footer-left">Copyright Iconic Fabric 2012.All rights reserved.</div>
        <div class="social_network">
                  <div class="social_text">
                      Follow Us On:
                </div>
                <div class="social_icon">
                      <a href="#"><img src="images/facebook.png" border="0" /></a>
                </div>
                <div class="social_icon">
                      <a href="#"><img src="images/twitter.png" border="0" /></a>
                </div>
                <div class="social_icon">
                      <a href="#"><img src="images/in.png" border="0" /></a>
                </div>
               
            </div>
    </div>
</div>
<div class="page">
          <div class="product-page-top"></div>
        <div class="product-page-cen">
              <div class="product-info-left">
                  <div class="product-heading"><h3>Photo Gallery</h3></div>
                  <div class="fl">
                        <img src="images/finished_product.jpg" border="0" width="460" height="453" />
                  </div>
            </div>
            <div class="product-info-right">
                  <h2 class="fl mt20">Pouffe</h2>
                <h4>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque quis eros nisi, in tempor turpis. Nulla sit amet erat nisl, nec viverra sapien. Mauris ultricies magna non nunc bibendum egestas. Etiam magna velit, volutpat ut semper at, vehicula in est. Nullam ultricies elit quis leo ultrices a porta arcu ullamcorper. Curabitur pharetra gravida tristique. Maecenas ac quam nisl,</h4>
                <div class="change-product">
                 <form>  
                    <div class="selection-line">
                          <div class="selection-label"><label>Fabric</label></div>
                          <select>
                              <option>Fabric1</option>
                            <option>Fabric2</option>
                            <option>Fabric3</option>
                        </select>
                        </div>
                    <div class="selection-line">
                          <div class="selection-label"><label>Product</label></div>
                          <select>
                              <option>Fabric1</option>
                            <option>Fabric2</option>
                            <option>Fabric3</option>
                        </select>
                   </div>
                   <div class="selection-line">
                          <div class="selection-label"><label>Color</label></div>
                        <select>
                              <option>Red</option>
                            <option>Green</option>
                            <option>Yellow</option>
                        </select>
                </div>
                  </form>                
                </div>
                <h2 class="fl mt20">Current Selction</h2>
                <div class="current-product">
                      <div class="current-fabric">
                          <img id="cf" src="" border="0" width="102" height="76" />
                        <h5>Fabric</h5>
                    </div>
                    <div class="current-product-image">
                          <img id="cp" src="" border="0" width="102" height="76" />
                        <h5>Product</h5>
                    </div>
                    <div class="add-btns">
                          <a href="javascript:;"><img src="images/add_enquiry.png" border="0" width="109" height="29" /></a>
                        <a href="javascript:;"><img src="images/add_basket.png" border="0" width="109" height="29" /></a>
                    </div>
                </div>
                <div class="product-detail">
                      <div class="product-label">PRICE:</div>
                    <div class="product-discription">£ 1320.00</div>
                    <div class="product-label">QUANTITY: </div>
                    <div class="product-discription"> 1</div>
                    <div class="product-label">Dimensions:</div>
                    <div class="product-discription">W: 87cm | H: 110cm | D: 113cm</div>
                    <div class="product-label">Fabric:</div>
                    <div class="product-discription">Fabric Name</div>
                </div>
            </div>
         
             
        </div>
       
        <div class="product-page-bot"></div>
    </div>
    <div class="footer">
          <div class="footer-left">Copyright Iconic Fabric 2012.All rights reserved.</div>
        <div class="social_network">
                  <div class="social_text">
                      Follow Us On:
                </div>
                <div class="social_icon">
                      <a href="#"><img src="images/facebook.png" border="0" /></a>
                </div>
                <div class="social_icon">
                      <a href="#"><img src="images/twitter.png" border="0" /></a>
                </div>
                <div class="social_icon">
                      <a href="#"><img src="images/in.png" border="0" /></a>
                </div>
               
            </div>
    </div>
</div>


</body>
</html>
searchsanjaysharmaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sudhindra A NCommented:
it has onther included js pages, could you please post a link to a sample test page ?
0
searchsanjaysharmaAuthor Commented:
Please find the whole code
Testiconic.zip
0
searchsanjaysharmaAuthor Commented:
Any updates
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

searchsanjaysharmaAuthor Commented:
testm is the relevant file
0
Sudhindra A NCommented:
Your code is working properly. Function f() is called on click of image.

but there is a problem in comparing the source attribute.

if you use "document.getElementById('i1').src" it will return complete url of the image (not exactly the one provided in the src attribute).

try alerting document.getElementById('i1').src just inside the function f().
0
searchsanjaysharmaAuthor Commented:
thats what how do i pick only images/product1.jpg
0
Sudhindra A NCommented:
use this..
alert($('#i1').attr('src'));
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
searchsanjaysharmaAuthor Commented:
How to pick the path starting from images.
0
searchsanjaysharmaAuthor Commented:
if(document.getElementById('i1').src=="testiconic/images/product1.jpg")
How to change on this
0
Sudhindra A NCommented:
if($('#i1').attr('src') == 'images/product1.jpg'){
//your code goes here..
}
0
searchsanjaysharmaAuthor Commented:
function f() is always giving same output.
of images/product1

function f()
{
if($('#i1').attr('src') == 'images/product1.jpg')
{
    alert($('#i1').attr('src'))
   
}
else if($('#i2').attr('src')=="images/product2.jpg")
{
    alert($('#i2').attr('src'))
}
else if($('#i3').attr('src')=="images/product3.jpg")
{
   alert($('#i3').attr('src'))
}
else if($('#i4').attr('src')=="images/product4.jpg")
{
   alert($('#i4').attr('src'))
}

   
}

 <li><a href="javascript:;"><img id="i1" src="images/product1.jpg" width="178" height="160" alt="" onclick="f()"/></a><h5>Cup</h5></li>
                    <li><a href="javascript:;"><img id="i2" src="images/product2.jpg" width="178" height="160" alt="" onclick="f()"/></a><h5>French Chair</h5></li>
                    <li><a href="javascript:;"><img id="i3" src="images/product3.jpg" width="178" height="160" alt="" onclick="f()"/></a><h5>Cushion</h5></li>
                    <li><a href="javascript:;"><img id="i4" src="images/product4.jpg" width="178" height="160" alt="" onclick="f()"/></a><h5>Pouffe</h5></li>
0
Sudhindra A NCommented:
that is because you are always checking for first image source attribute, which is true in all cases.

change it to..
function f(e)
{
	
if($('#'+e.id).attr('src')=="images/product1.jpg")
{
    alert('Product1 selected : '+$('#i1').attr('src'));
}
else if($('#'+e.id).attr('src')=="images/product2.jpg")
{
	alert('Product2 selected : '+$('#i2').attr('src'));
}
else if($('#'+e.id).attr('src')=="images/product3.jpg")
{
	alert('Product3 selected : '+$('#i3').attr('src'));
}
else if($('#'+e.id).attr('src')=="images/product4.jpg")
{
	alert('Product4 selected : '+$('#i4').attr('src'));
}

    
}

Open in new window


and html to

<li><a href="javascript:;"><img id="i1" src="images/product1.jpg" width="178" height="160" alt="" onclick="f(this)"/></a><h5>Cup</h5></li>
                    <li><a href="javascript:;"><img id="i2" src="images/product2.jpg" width="178" height="160" alt="" onclick="f(this)"/></a><h5>French Chair</h5></li>
                    <li><a href="javascript:;"><img id="i3" src="images/product3.jpg" width="178" height="160" alt="" onclick="f(this)"/></a><h5>Cushion</h5></li>
                    <li><a href="javascript:;"><img id="i4" src="images/product4.jpg" width="178" height="160" alt="" onclick="f(this)"/></a><h5>Pouffe</h5></li>

Open in new window

0
searchsanjaysharmaAuthor Commented:
ok
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.