I'm looking for a way to convert an uppercase file extension to lowercase so that the following code works <a href="<%GALLERYPAGE%>"><img src="myCode">[/url]
I wrote the following which includes some JavaScript ... however my knowledge of JS is very poor due to lack of use and my script is not working.
In the following the variable <%IMAGENAME%> converts to whatever like DSCN3826.JPG
my procedure extract (str.substring(0,8)+".jpg") converts the file extension in the file name ><%IMAGENAME%>
to what I need and I want src to equal (str.substring(0,8)+".jpg")
how do I get src to recognize the result of (str.substring(0,8)+".jpg")?
<html>
<head>
<title><%IMAGENAME%></title>
</head>
<body bgcolor="#FFFFFF">
<script type="text/javascript">
var str="<%IMAGENAME%>"
(str.substring(0,8)+".jpg")
<center>
<a href="page1.htm"><img src="get.str">[/url]
</script>
<br>
<a href="DSCN3942.htm">Previous Image[/url]
<a href="DSCN3827.htm">Next Image[/url]
</center>
</body>
</html>
mozerd;
Quote:I'm looking for a way to convert an uppercase file extension to lowercase so that the following code works <a href="<%GALLERYPAGE%>"><img src="myCode">[/url].....
<a href="page1.htm"><img src="get.str">[/url]
Try this:
<a href="page1.htm"><img src="
jget.str">[/url]
Should work,
n'est-ce-pas?
Oddysey
mozerd;
Quote:Thnaks, however scr does not display the result of
"jget.str" ... <_<
Well, I was just shootin' from the hip... :P
In that case, assign the results of get.str to a variable within your script. Then,
don't quote it when using in the img tag, like this:
<img src=
var_name width="xx" border="1"> will now do the trick.
In some cases, you might need to preface the var_name with the javascript declaration, as I showed you in my previous post:
jvar_name. In my experience, most browsers work fine without it, though, so try it the simple way first.
Oddysey
Oddysey Wrote:<img src=var_name width="xx" border="1"> will now do the trick.
In some cases, you might need to preface the var_name with the javascript declaration, as I showed you in my previous post: jvar_name. In my experience, most browsers work fine without it, though, so try it the simple way first.
I gave it a shot -- but you suggestion does not work. And thanks for the effort.
BTW, my browser is IE 6. and my code now looks like the following:
============
<html>
<head>
</head>
<body bgcolor="#FFFFFF">
<title><%IMAGENAME%></title>
<center>
<script type="text/javascript">
var str="<%IMAGENAME%>"
var myimager=(str.substring(0,8)+".jpg")
</script>
<a href="<%GALLERYPAGE%>"> <img src=myimage>[/url]
<br>
<a href="<%PREVIOUSIMAGEPAGE%>">Previous Image[/url]
<a href="<%NEXTIMAGEPAGE%>">Next Image[/url]
</center>
</body>
</html>
============
I tried src="myimage" and src=j
myimage and src="j
myimage" to no avail. [beatdown]
Made a typo mistake in the var declaration - however after changing src=myimage to src=myimager the issue remains.
You cannot use the "myimage" variable that way in a "j
" link, because the browser thinks that the content of "myimage" is the actual image (and not its location).
But you can let the script write that link:
Code:
<HTML>
<HEAD>
<TITLE>DSCN3942.JPG</TITLE>
</HEAD>
<BODY>
<center>
<a href="something">
<script type="text/javascript">
var str = "DSCN3942.JPG";
str = str.substring(0,8) + ".jpg";
document.write('<img src="' + str + '">')
</script>
</a>
</center>
</BODY>
</HTML>
Also:
- If the image name part doesn't always have a constant number of chars, you could use <span style='color:blue'>str.match</span> and <span style='color:blue'>str.slice</span>. See
DevGuru.
- The Mozilla browsers and Opera have a JS console which is great for checking if the code is written correctly.
sidki
mozerd;
Ummm, maybe I'm being dense here, but let me quote two lines of your code here:
Code:
var str="<%IMAGENAME%>"
var myimager=(str.substring(0,8)+".jpg")
I
*think* that you are making a string out of an environment variable, and in that string you are including two characters, the < and > symbols. If those two are included in your overall string, then that trailing > symbol is gonna show up in your substring (0,8) operation, and that's never gonna be a valid file name.
Moreover (I'm sure you already know this, but I wanna cover my butt here), unless all of your file names are exactly 8,3 chars in length, then your substring operation won't be 100% reliable.
Perhaps we should be attacking this from another direction, eh? Lemme think about this for a night or two, and I'll get back to you. Of course, don't hesitate to post sooner, I'll still be reading, but I'm gonna do some research, and maybe even think ahead a little bit before shooting off my mouth! :o [lol]
Oddysey
sidki3003 Wrote:But you can let the script write that link:
sidki
that works -- and works just great! You're a genius
Thank you.
If anyone is wondering the following is what the final code looks like [btw, all my jpeg files are 8,1,3 total of 12 characters; the 1 represents a period]
Code:
<HTML>
<HEAD>
<TITLE><%IMAGENAME%></TITLE>
</HEAD>
<body bgcolor="#FFFFFF">
<center>
<a href="<%GALLERYPAGE%>">
<script type="text/javascript">
var str = "<%IMAGENAME%>";
str = str.substring(0,8) + ".jpg";
document.write('<img src="' + str + '">')
</script>
</a>
<br>
<a href="<%PREVIOUSIMAGEPAGE%>">Previous Image</a>
<a href="<%NEXTIMAGEPAGE%>">Next Image</a>
</center>
</body>
</html>
sidki3003 Wrote:See DevGuru.
- The Mozilla browsers and Opera have a JS console which is great for checking if the code is written correctly.
sidki, the DevGuru site you provided is a
wealth of information -
Thanks
and where I found the following
replace() method which IMO is better suited
where the number of characters may not be constant.
Code:
<html>
<body>
<script type="text/javascript">
myString = new String("DSCN3826.JPG")
rExp = /.JPG/gi;
newString = new String (".jpg")
results = myString.replace(rExp, newString)
document.write(results)
</script>
</body>
</html>
Cool!

-- You may want to leave out the case-insensitive flag.