Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract a portion of a string ( or URL) - use of .length? 1

Status
Not open for further replies.

das1406

Instructor
Jul 14, 2006
10
NZ
Re a slideshow there is a downloadable demo (with code) having several options at:
I have a question relating to the code from this site. (See end for code) It uses a form & part of the output displays the URL of the image/picture. I wish to truncate the first 18 characters of the URL (directory portion etc) and the last four, the extension (.jpg etc). The **** line illustrates this. The ++++ line is meant to obtain the length of the URL, less 4.
Removing the -4 gives output deleting the first 18 chars, but leaves on the extension. How do I get the appropriate value?

function showAd() {
var srcobject;
var lengthstr = eval(document.slide.tit.length)-4; //++++
document.slide.tit.value=adImages[thisAd].substring(18,lengthstr); //****
document.adBanner.src = adImages[thisAd];

. . . and in the 'body' part is a line

<input name="tit" type="text" size="30" readonly="readonly">
referring to a TextField for the title "tit"
Any help would be most appreciated.
David
 
Try replacing these two lines:

Code:
var lengthstr = eval(document.slide.tit.length)-4; //++++
document.slide.tit.value=adImages[thisAd].substring(18,lengthstr); //****

with these:

Code:
var lengthstr = adImages[thisAd].length;
document.forms['slide'].elements['tit'].value = adImages[thisAd].substr(18, lengthstr - 22);

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hallelujah! Thanks Dan, You're the Man!;-) The code worked perfectly first time. great stuff.
David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top