473,789 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using getElementById to get img.src.value and applying to other stuff...

1 New Member
hi guys,

My first post yes. Thanks for all the nice posts and threads in this forum - great stuff.

Now, here's my question:

First off, the url : http://catfish.businesscatalyst.com/bcimg.htm

When you get there an alert of the div/img name in question appears. It splits and grabs the 'name' from images/name.jpg.

If you look at the source, this value is set to var = bb.

My problem now is to apply this throughout this little script(s). What I want to do is take this var 'bb', and concatenate a '_back' to it so its something like 'name_back.jpg' . You see something similar in the script source ( toggleDisplay() function).

What this does is swap the 'view back'/'view front' image of a swimsuit, and i want it to grab 'preloaded' image (by a CMS) hence the var bb, then be able to pull the name_back.jpg image when you swap it in the script.

For some reason when I replace toggleDisplay(' look_in_source_ for_name_here') with 'bb', it doesn't work. I'm pretty terrible with JS.


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <script language="javascript">
  4.  
  5.     //preset toggleDisplay()
  6.     imgDir='front';
  7.  
  8.  
  9. function findImgPath(){
  10.     var bgImg = document.getElementById('product_normal').getElementsByTagName('img')[0].src;
  11.  
  12.     var a = bgImg.split("/");
  13.     var a_length = a.length-1;
  14.     var aa = a[a_length];
  15.  
  16.     var b = aa.split(".");
  17.     var b_length = b.length;
  18.     var src = b[0];
  19.  
  20.     //alert(bgImg); //full bgImg string
  21.     //alert(a); //elements in array of bgImg string
  22.     //alert(aa); //full image name
  23.     //alert(bb); //image name without filetype
  24.  
  25.      //var src = bb;
  26.     //alert("src = " + src);
  27. }
  28.  
  29.  
  30.  
  31.  
  32. function toggleDisplay(){
  33. <!--
  34.  
  35.     var element = document.getElementById('product_normal').style;
  36.  
  37.         if (element.display=='none') {
  38.             element.display='block';
  39.              } else {
  40.                 element.display='block';
  41.                     }
  42.  if (imgDir=='front')
  43.      {
  44.         document.getElementById('swapImg').src='images/view_back.gif';imgDir='back';
  45.         document.getElementById('product_normal').innerHTML = "<a href=\"images/womens/sale/large/"+src+".jpg\" target=\"_blank\"><img src=\"images/womens/sale/"+src+".jpg\" border=\"0\"></a>"; alert("front " + src);
  46.              } else {
  47.                 document.getElementById('swapImg').src='images/view_front.gif';imgDir='front';
  48.                 document.getElementById('product_normal').innerHTML = "<a href=\"images/womens/sale/large/"+src+"_back.jpg\" target=\"_blank\"><img src=\"images/womens/sale/"+src+"_back.jpg\" border=\"0\"></a>"; alert("back " + src);
  49.                     }
  50.              }
  51.  
  52. //->
  53. </script>
  54. </head>
  55. <body onLoad="javascript:findImgPath();">
  56.   <a href="javascript:toggleDisplay();"><img src="images/view_back.gif" border="0" id="swapImg"/></a>
  57. <div style="display:block;" id="product_normal"><img src="images/womens/sale/cf_single_blue_med.jpg" border="0"></div>
  58.  
  59. </body>
  60.  
  61.  

I'd much appreciate the help - thanks for taking the time to read this.

Cheers

Mike
May 22 '07 #1
1 38726
acoder
16,027 Recognized Expert Moderator MVP
There are opening HTML comments in toggleDisplay() (line 31).
Jan 29 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2707
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff working, but it only worked for IE. You can see a working version here: http://www.publicpen.com/designer/mcControlPanel.php username: designer password: designer123 However, I've tried to rewrite this so it would work in all browsers,
4
5485
by: lawrence | last post by:
Can anyone tell me why this code works in Netscape 7.1 but not in IE??? <SCRIPT type='text/javascript'> function makeVisible(nameOfDiv) { document.getElementById(nameOfDiv).style.visibility='visible'; document.getElementById(nameOfDiv).style.height='auto'; if (nameOfDiv != 'weblogs')
2
125417
by: Ant | last post by:
Ok, so I have a regular input textbox on my webpage and I'm trying to work out how to make it so when the user presses a button the the textbox holds the value of a variable. I just can't work out how to do this. any help much appreciated
3
2442
by: vanisathish | last post by:
Hi I am running a client side javascript timer to periodically refresh the contents of some tables in the HTML page. The table values are dynmically binded from XML DOM object using the <XML tag in HTML>. The data is getting updated properly. but whenever the value is refreshed, the HTML page flickers. How do i avoid this flickering.. below is my html page <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
5
2837
by: Mardy | last post by:
I have an aspx page that contains a drop down and 3 divs and lots of other stuff. I'd like to hide the divs depending on which option from the drop down is selected. It works fine until I do a postback then all 3 divs are visible. When the page initially loads I see just the div corresponding to the default value in the ddl. Prior to a postback the display works as intended but once a postback occurs all 3 divs are visible until I make...
5
2508
by: jose1lm | last post by:
What is supposed to happen: A user enters data into one of the FORM input selections. When the user submits the form, the onclick event is supposed to go to a function that will set another FORM value (SearchSel) to some number that will be used on the next page. The javascript function 'setSelx' doesn't work in FireFox but works with the other browsers. Can someone help to fix this code or point me in the right direction? Server:...
2
3174
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand whats the prob.this is the code i m using: <? include("config.inc.php"); //error_reporting(0); ...
10
9115
by: sowmyati | last post by:
HI All, I am new to javascript. I have snippet wherein i am giving a brief note on what i am trying to do. In the below have a variable by name stuff. trying to reset the page. Part of the code which does reset is attached below. there is a reset button which will reset the connection and it takes two min for data loading during which the reset button has to be disabled and later after two mins it should enable the button for the user. ...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.