[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2012-03-21
13
Medium Priority
?
314 Views
Last Modified: 2012-06-22
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>
0
Comment
Question by:searchsanjaysharma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
13 Comments
 
LVL 13

Expert Comment

by:ansudhindra
ID: 37750794
it has onther included js pages, could you please post a link to a sample test page ?
0
 

Author Comment

by:searchsanjaysharma
ID: 37750916
Please find the whole code
Testiconic.zip
0
 

Author Comment

by:searchsanjaysharma
ID: 37751113
Any updates
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:searchsanjaysharma
ID: 37751242
testm is the relevant file
0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 37751273
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
 

Author Comment

by:searchsanjaysharma
ID: 37751333
thats what how do i pick only images/product1.jpg
0
 
LVL 13

Accepted Solution

by:
ansudhindra earned 2000 total points
ID: 37751349
use this..
alert($('#i1').attr('src'));
0
 

Author Comment

by:searchsanjaysharma
ID: 37751755
How to pick the path starting from images.
0
 

Author Comment

by:searchsanjaysharma
ID: 37751809
if(document.getElementById('i1').src=="testiconic/images/product1.jpg")
How to change on this
0
 
LVL 13

Expert Comment

by:ansudhindra
ID: 37751842
if($('#i1').attr('src') == 'images/product1.jpg'){
//your code goes here..
}
0
 

Author Comment

by:searchsanjaysharma
ID: 37751881
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
 
LVL 13

Expert Comment

by:ansudhindra
ID: 37751940
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
 

Author Closing Comment

by:searchsanjaysharma
ID: 37813052
ok
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question