473,769 Members | 2,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert ALT to Caption

I found a script that converts image alt text to a caption which I've tried
to modify for my needs:

function addCaption(imgE lem) {
var captionElem = document.create Element("div");
captionElem.cla ssName = "caption";
var captionText = document.create TextNode(imgEle m.alt);
captionElem.app endChild(captio nText);
if(imgElem.next Sibling)
imgElem.parentN ode.insertBefor e(captionElem,i mgElem.nextSibl ing);
else
imgElem.parentN ode.appendChild (captionElem);
with(imgElem.st yle) {
captionElem.sty le.width =
(imgElem.width+ borderLeftWidth +borderRightWid th+paddingLeft+ paddingRight)+" px";
}
return true;
}

<img src="forest.jpg " width="515" height="183" alt="Strathyre Forest at
Dawn - the forest is bathed in golden light and mist rises from between the
trees - &copy; Roy Reed, 1987" onload="javascr ipt:addCaption( this)">

This works as I want if no border or padding is added to the image, but not
if they are. In IE6 the padding is added to the width of the created div,
but not the border width. In Firefox nothing is added.
Can anyone tell me how this should be coded.

Live example (with attribution to original code) at
www.reeddesign.co.uk/autocaption/

Thanks

Roy Reed
Aug 14 '06 #1
3 1482

Roy Reed написав:
with(imgElem.st yle) {
captionElem.sty le.width =
(imgElem.width+ borderLeftWidth +borderRightWid th+paddingLeft+ paddingRight)+" px";
}
You add string values.

<img width="500px"st yle="padding: 5 5 5 5">
In this case instead of "510px" you will get "500px5px5p xpx"
Use parseInt or parseFloat before summation.

Aug 15 '06 #2

"marss" <ma***@ukr.netw rote in message
news:11******** **************@ i3g2000cwc.goog legroups.com...

Roy Reed ???????:
> with(imgElem.st yle) {
captionElem.sty le.width =
(imgElem.width +borderLeftWidt h+borderRightWi dth+paddingLeft +paddingRight)+ "px";
}
>You add string values.

<img width="500px"st yle="padding: 5 5 5 5">
In this case instead of "510px" you will get "500px5px5p xpx"
Use parseInt or parseFloat before summation.
Is this what you meant?

with(imgElem.st yle) {
captionElem.sty le.width = parseFloat(imgE lem.width+borde rLeftWidth+
borderRightWidt h+paddingLeft+p addingRight)+"p x";
}

It gives exactly the same result.

Thanks for trying to help with this. I'm not a JavaScript expert.

Roy
Aug 15 '06 #3

Roy Reed написав:
Is this what you meant?

with(imgElem.st yle) {
captionElem.sty le.width = parseFloat(imgE lem.width+borde rLeftWidth+
borderRightWidt h+paddingLeft+p addingRight)+"p x";
}
No. I mean something like this
with(imgElem.st yle) {
captionElem.sty le.width =
(parseFloat(img Elem.width)+par seFloat(borderL eftWidth)+

parseFloat(bord erRightWidth)+p arseFloat(paddi ngLeft)+parseFl oat(paddingRigh t))+"px";
}

Aug 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3948
by: Wally | last post by:
I would like to have an image with a caption displayed below it. The size of the image will vary. The caption should not extend beyond the width of the image. How can I cause the text of the caption to wrap so that it will stay within the (varying) width of the image? Any ideas?
2
16219
by: Phil Stanton | last post by:
When designing a new form or report, the Default ForeColor is often something like -2147483640 which is the colour of Windows text (possibly black) and the default backColor is -2147483643 (possibly white) Can anyone tell me how to convert these colours to either RGB colours or the Long number used by Access. Black is 0 and White is 16777215 ...
1
1823
by: altacct | last post by:
I've got a multi-page subform with a tab control on one of the pages. The code that moves you from page three to page four, which is where the tab is, changes the tab captions according to some information stored in a table. Only it's not working. Actually, it is working, and then it's unworking. The tab caption starts out "And...". Depending on what's in the table, the caption may get changed to "Or...". Here's the code that makes...
2
12198
by: Mel WEaver | last post by:
Hello, I have the following delphi structure for a binary file. I'm looking for idea how to read this file. Mel type TMenuDataStruct = packed record exename : string;
0
3050
by: Chenghui Li | last post by:
We have a problem with the Windows XP theme: We have a IDE which allows other developers to develop visual programs for their customers. Our IDE allow them to set font for window captions easyly (through a dialog). It works fine fo W98, 2000, NT, and XP is the theme is Classic. But on XP if the theme is "Windows XP", the we have a problem: if the developer set the caption font to be say, "Script" (and all non-default font), then the...
11
1825
by: John Ortt | last post by:
Hi everyone. I have a database which I have developed in Access 2000 which is working nicely. The problem is that my customer only has Access 97. I tried to convert the database but the main menu won't work. I has two parts, a mainmenu and a submenu which displays the option buttons.
6
3215
by: Bob Darlington | last post by:
I want to use the caption property for fields in a recordset as a condition in a loop. That is, I only want to consider those fields which have captions: For each fld in RecordsetName.Fields If fld.Properties("Caption") <"" then do something The problem is that all fields are included, even those with no caption set. I've tried IsMissing, IsEmpty and IsNull for the test but none will filter
9
7275
by: Neal | last post by:
http://www.brassattackofspringfield.com/gigs.html CSS at http://www.brassattackofspringfield.com/default.css Opera and IE render caption as desired. Firefox does not. Why? And is there a fix?
7
1555
by: jimmy1 | last post by:
Hello everyone I am trying to find a way to convert seconds to minutes in the script below - Private Sub cmdBegin_Click() On Error Resume Next n = Val(txttime.Text) * 60 tmrClock.Enabled = True cmdStop.Enabled = True End Sub
0
9579
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
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
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
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
5293
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
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.