473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

1
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 38691
acoder
16,027 Expert Mod 8TB
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
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...
4
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) {...
2
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...
3
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...
5
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...
5
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...
2
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...
10
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...

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.